Time calculating

Hello there,
I need to count difference of two time inputs in HH:MM format to Calculation field.
If I use field type Number and input single hour (e.g. 5 to 15), it works fine. But I need count the hour format above, e.g. 05:30 to 16:30.

Any suggestions? Thanks in advance.
OS

Hello Ondrej,

I am sending you the answer to your question bellow:

Math.floor(({endDate} - {startDate})/60000/60).toString().padStart(2, '0') + ':' +  Math.ceil(({endDate} - {startDate})/60000%60).toString().padStart(2, '0');

(The data type of the field must be Text.)

Have a beautiful day.

With kind regards,
Soňa

Thank you, Soňa, for your reply. Not exactly it but you helped me find my way.:slight_smile:

Thanks, have a nice day.
Regards, OS.

Still juggling with time parsing…

Is it possible to split Text field (eg. Time1, value 8:45) variable in a calculation field (eg. Res, output Text) by something like:

let array = {Time1}.split(‘:’);
let hh = array[0];
let mm = array[1];

?
I am getting .

Thanks in advance.

Hello Ondrej,


field: Date and time 1 - > Date & time data type
field: Date and time 2 - > Date & time data type
field: Date and time 3 - > Text data type


Result in edit form

JS:

let diff = doo.model.<[Date and time 2 (dateAndTime2)]>.value - doo.model.<[Date and time 1 (dateAndTime1)]>.value;
  doo.model.<[Date and time 3 (dateAndTime3)]>.value = Math.floor(diff/60000/60) + ':' +  Math.ceil(diff/60000%60).toString().padStart(2, '0');

Scripting area

Hope it works well now :slight_smile:

With kind regards,
Soňa