datediif for Number of minutes between two times that falls on different days

Yobi4ever

Registered User.
Local time
Today, 19:19
Joined
Feb 2, 2006
Messages
14
Dear,

I am using datediff function to get the number of miunutes between to times: Me.WorkedMinutes = DateDiff("n", [OTIn], [OTOut]) and it works oK EXCEPT when I'm computing the minutes between two times that falls in different days. for exmaple number of minutes or hours worked betwen 24.02.2013 from 16:09 to 25.02.2013 00:03 then i get -966!!

Can someone please let me know how to workaround this issue?
Thank you.
 
For the absolutely general case of difference in minutes between two arbitrary dates and times, you can try this, where DT1ST and DT2ND are the first and second times:

DIFFMIN = CLNG( 1440.0 * ( CDBL( DT2ND ) - CDBL( DT1ST ) ) )

This works because:

a) 1440 = 24 * 60 = minutes per day

b) Date/time values are stored as days and fractions of a day between the current date and a reference date. You can work out the proof if you wish, but basically the difference between two numbers that are relative to the same point is the difference between the two numbers no matter what point they have in common, mostly based on the concept of addition and subtraction being associative math operations.

Now, you MIGHT need to adjust this to take into account whether you got any sleep during that interval. I.e. computing the minutes this way does not allow for someone going home after work and coming in the next morning. However, if all you wanted was really the raw minutes, that is how you would compute it.
 
Hi The_Doc_Man,

I tried your solution but I still got the same result.
 

Users who are viewing this thread

Back
Top Bottom