18
Views
7
Comments
Solved
Different between two times
Question

Hi Friends,

      I am having two-time variable when I get different between from and to time, its not coming as expected, please anyone can help for the below scenario.

For example:

       My start time is 3:00:22 and my end time is 03:27:11 so here I am using to get the diff between these two time is

NewTime(DiffHours(StartTime,EndTime),Mod(DiffMinutes(StartTime,EndTime),60),Mod(DiffSeconds(StartTime,EndTime),60)

its giving 00:27:49 instead of 00:26:49, can any one help on these scenario.


Thank you.

Rank: #89
Solution

Hi Balaji,

DiffMinutes return only in minute diffrence.

Use this expression-

NewTime((DiffSeconds(StartTime,EndTime)/3600),Mod(DiffSeconds(StartTime,EndTime)/60,60),Mod(DiffSeconds(StartTime,EndTime),60))

It will give you actual result.


Hope this will help you.

Regards

Rahul

mvp_badge
MVP
Rank: #67

Hello Balaji.


Let's see this step by step:

  • DiffHours between 3 and 3 is 0.
  • DiffMinutes between 3:0 and 3:27 is 27 (the seconds are ignored if you check the documentation).
  • DiffSeconds between 3:00:22 and 3:27:11 is 1609. Mod(1609,60)=49

0 hours, 27 minutes and 49 seconds.So the value is right.


The ideal way is to work with seconds only NewTime(0,0,DiffSeconds(StartTime,EndTime)) will give you the right time.

Rank: #89

Welcome @Balaji..

Cheers

mvp_badge
MVP
Rank: #67

No problem.

A small correction on my formula: it is not NewDate(0,0,DiffSeconds(Time1,Time2)). Because the number of seconds in invalid.

But it works on AddSeconds(NullDate(),DiffSeconds(Time1,Time2))


mvp_badge
MVP
Rank: #19

Hi all,

Just a warning on using DiffSeconds, when using to calculate time between dates longer apart from each other than 68.10 years:

The maximum supported value is (2^31)-1 seconds. This corresponds to approximately 68.10 years. If DiffSeconds(dt1, dt2) is bigger than (2^31)-1, you will get an unexpected value. 

Regards,

Daniel