Calculating duration

Hello,

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.

It would be great if you can support me.

Thank you and best regards,
Daniel

char data_results_0_start_time = data_results_0["start_time"];

Eight bits for all that?

It would be great if you can support me.

It would be great if you would post your code.
In code tags.

Hello,

char data type can hold only one character, so the value of the variable is '2' (first character of "2019-12-24 09:00:00")

Instead of dates, can't you store unix timestamps? Then it will be much easier to calculate time differences.

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:
Is it correct to define the variables as char?

Only if they are a single character!

What would be the right variable definition if it's not 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.

Example here :

How to split string into ints LibFYH - Online C++ Compiler & Debugging Tool - Ideone.com

How to calculate time difference XtoXGw - Online C++ Compiler & Debugging Tool - Ideone.com