I'm really struggling with the time function in ARduino as I want to calculate the minutes between the start and the end time of two variable I receive via JSON.
These are the two variables:
char data_results_0_start_time = data_results_0["start_time"]; // value of the variable : "2019-12-24 09:00:00"
char data_results_0_end_time = data_results_0["end_time"]; // value of the variable : "2019-12-24 09:59:59"
To calculate the minutes I used the time.h libarary and the following:
Serial.println(minute(data_results_0_end_time)-minute(data_results_0_start_time));
It's compiling without an error but I allways get 0 as result.
I get date end time from a website via Json in exactly the following format "2019-12-24 09:00:00".
Now I don't know how to progress from here and calculate the dueation.
How can I convert the above into Unix time?
Is it correct to define the variables as char?
DanielTwo:
What would be the right variable definition if it's not char?
Whatever type the JSON library returns for string fields.
String, probably.
But I have never used it, so I don’t know for certain other than a single char (single byte) is NOT correct.
Check the library examples to find out.
You can split the string into variables, then use function makeTime from the time library to get unix timestamps, then simply substract to get the time difference in seconds.