516
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.

2026-02-26 06-29-24
Rahul
Ā 
MVP
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

2021-03-30 13-44-25
Balaji Ravikumar

Rahul Sahu wrote:

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

 

 Thank you Rahul

It working as you said.

2016-04-22 00-29-45
Nuno Reis
Ā 
MVP

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.

2021-03-30 13-44-25
Balaji Ravikumar

Nuno Reis wrote:

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.

 Thank you Nuno for your guidance.

 

2026-02-26 06-29-24
Rahul
Ā 
MVP

Welcome @Balaji..

Cheers

2016-04-22 00-29-45
Nuno Reis
Ā 
MVP

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))


2024-07-05 14-16-55
Daniël Kuhlmann
Ā 
MVP

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


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.