How can I get the difference between two hours, in 0 to 24 format?

Example: If I have 23:50 and 00:10, I would like to get as a result of the difference "00:20". 


Or If I have 00:30 and 00:10, I would like to get "-00:20" (in negative).


There's a way to make it?


Thank you so much!

Hi Julia,

Have you tried BuitIn function- DiffMinutes()



Use this ,you will get result as you want.


Regards

Rahul Sahu

Rahul Sahu wrote:

Hi Julia,

Have you tried BuitIn function- DiffMinutes()



Use this ,you will get result as you want.


Regards

Rahul Sahu

 Hi! Yes, I have tried, but I have problems when the minutes is bigger than 60. There's a way to count as hours when I have this situation?

 

Hi Julia,

Use NewTime () function and use calculation for time like below image

Create a one variable (time data type ) for that hold diff of time- 

NewTime(DiffMinutes(DateTimeVar,DateTimeVar2)/60,Mod(DiffMinutes(DateTimeVar,DateTimeVar2),60), NullIdentifier())


And result is 

See Demo- https://rahul-sahu.outsystemscloud.com/TestEvent/Demo?_ts=637301962338955722 


Hope this will help you.

Regards

Rahul Sahu

Rahul Sahu wrote:

Hi Julia,

Use NewTime () function and use calculation for time like below image

Create a one variable (time data type ) for that hold diff of time- 

NewTime(DiffMinutes(DateTimeVar,DateTimeVar2)/60,Mod(DiffMinutes(DateTimeVar,DateTimeVar2),60), NullIdentifier())


And result is 

See Demo- https://rahul-sahu.outsystemscloud.com/TestEvent/Demo?_ts=637301962338955722 


Hope this will help you.

Regards

Rahul Sahu

 Hi! Yes, it helped me. Thank you.


But the problem is with the 0 to 24 format. When I have, for example, to calculate the difference between "02:04" and "19:00", I would like to have "07:04" but I have "00:00:00" (in yellow). In the next line in the image, the result is ok.


 

Julia Freitas wrote:

Rahul Sahu wrote:

Hi Julia,

Use NewTime () function and use calculation for time like below image

Create a one variable (time data type ) for that hold diff of time- 

NewTime(DiffMinutes(DateTimeVar,DateTimeVar2)/60,Mod(DiffMinutes(DateTimeVar,DateTimeVar2),60), NullIdentifier())


And result is 

See Demo- https://rahul-sahu.outsystemscloud.com/TestEvent/Demo?_ts=637301962338955722 


Hope this will help you.

Regards

Rahul Sahu

 Hi! Yes, it helped me. Thank you.


But the problem is with the 0 to 24 format. When I have, for example, to calculate the difference between "02:04" and "19:00", I would like to have "07:04" but I have "00:00:00" (in yellow). In the next line in the image, the result is ok.


 

 It's because I'm working only with time, I'm not using date. So, I don't know if it's possible to get the result that I want only with the time information.

 

Julia Freitas wrote:

Julia Freitas wrote:

Rahul Sahu wrote:

Hi Julia,

Use NewTime () function and use calculation for time like below image

Create a one variable (time data type ) for that hold diff of time- 

NewTime(DiffMinutes(DateTimeVar,DateTimeVar2)/60,Mod(DiffMinutes(DateTimeVar,DateTimeVar2),60), NullIdentifier())


And result is 

See Demo- https://rahul-sahu.outsystemscloud.com/TestEvent/Demo?_ts=637301962338955722 


Hope this will help you.

Regards

Rahul Sahu

 Hi! Yes, it helped me. Thank you.


But the problem is with the 0 to 24 format. When I have, for example, to calculate the difference between "02:04" and "19:00", I would like to have "07:04" but I have "00:00:00" (in yellow). In the next line in the image, the result is ok.


 

 It's because I'm working only with time, I'm not using date. So, I don't know if it's possible to get the result that I want only with the time information.

 

 No, It is happening,because it will return negitive value and negitive value not divided thats why you geeting

00:00:00.

Can do one thing check diff is Negitive or positve if diff is positive go as same flow it is working 

and negitive flow first multiply by - sign it will convet as positive value  and do your calution and after calculation is complete show - sign before hours,

see again demo with above link

https://rahul-sahu.outsystemscloud.com/TestEvent/Demo?_ts=637301962338955722


Regards

Rahul Sahu 

Hello Julia,

It is possible, as far as you know the day that you want to compare. In this particular situation, it seems that you want to compare always with the previous day, so you can do it.

First thing, you need to verify if the second time is greater than the first one. If it is, you apply the math that you have right now:

T2 = 20:47

T1 = 17:40

T1 <= T2

Result = T2 - T1 = 20:47 - 17:40 = 03:07


Second, if the second time is smaller (less) than the first one, you need to do the math to compare to that time from the previous day.

T2 = 02:04

T1 = 19:00

T1 > T2

You just need to create a new time with 23:59 value and subtract the T1 value to it.

23:59 - 19:00 = 04:59

Then you add the T2 value to the result, plus 1 minute.

04:59 + 00:01 + 02:04 = 05:00 + 02:04 = 07:04


This will allow you to get the result that you want.


Kind regards,

Rui Barradas

Rui Barradas wrote:

Hello Julia,

It is possible, as far as you know the day that you want to compare. In this particular situation, it seems that you want to compare always with the previous day, so you can do it.

First thing, you need to verify if the second time is greater than the first one. If it is, you apply the math that you have right now:

T2 = 20:47

T1 = 17:40

T1 <= T2

Result = T2 - T1 = 20:47 - 17:40 = 03:07


Second, if the second time is smaller (less) than the first one, you need to do the math to compare to that time from the previous day.

T2 = 02:04

T1 = 19:00

T1 > T2

You just need to create a new time with 23:59 value and subtract the T1 value to it.

23:59 - 19:00 = 04:59

Then you add the T2 value to the result, plus 1 minute.

04:59 + 00:01 + 02:04 = 05:00 + 02:04 = 07:04


This will allow you to get the result that you want.


Kind regards,

Rui Barradas

 Hi ! Thank you for your answer. It almost allow me to get the result that I want.


If I have, for example, 

T2 = 18:00

T1 = 19:00

Then, T1 > T2. And if I use the logic of substract 23:59, I will not get 01 hour.


 

Hi Julia,

Don't forget that the day also counts. In your scenario it should be something like:

1)

T2 = 19:00 (today)

T1 = 18:00 (today)

Then T1 <= T2, so the result is T2 - T1 = 19:00 - 18:00 = 01:00 hour


2)

T2 = 18:00 (today)

T1 = 19:00 (yesterday)

Then T1 > T2, so the result is 23:59 - 19:00 = 04:59 + 00:01 = 05:00 + 18:00 = 23:00


It always depend on the date.


According to your example, I was assuming that when T1 is greater than T2, than T1 is from yesterday.


Kind regards,

Rui Barradas