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! 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?
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.
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:
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
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:
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
Then, T1 > T2. And if I use the logic of substract 23:59, I will not get 01 hour.
Hello Rui,
How do you actually calculate hours and minutes difference when the datatype is Time or Text?
E.g.
T2 -> 07:30
T1 -> 00:40
T2 >= T1
So, T2-T1 = 06:50
I understand the logic in practice. But in OutSystems, how can I achieve this?
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.
I think that we can't make negative Time as class. But we can present it like Text.
You can use this in expression. It's very simple, but before you need calculate difference in seconds (it can be negative because result of function DiffSeconds (t1,t2) can be negative.
See It in attached image.