Time Calculation

chad101

Registered User.
Local time
Yesterday, 19:07
Joined
Dec 31, 2005
Messages
56
I have two text boxes which store medium times (hh:mm Am/Pm). How can I calculate the time difference for these two medium times (Start = 11:00Pm, Stop = 12:15Am = 75 minutes)? I know the time difference will never exceed 24hrs. So I don’t need the dd/mm/yy. Could someone point me in the right direction or give an example?

Thanks, Chad
 
Create an unbound text box with row source =[Your start field name]-[Your stop field name]
Set its format to short time.
 
I have been looking at something similar. Access stores the time in the decimal part of a number. This goes down to seconds. To be useful and accurate the time must be converted to an integer. If you need the seconds then this must be a long integer. I favour losing the seconds which allows integer minutes to fit into an integer. We need two functions one to convert MS time to minutes and one to convert minutes to decimal time. Haven't yet written either I'm afraid. Maybe someone will get there first.
 
try

=(Format(stop-start],"hh")*60)+Format(stop-start,"nn")

Brian
 
Works, unless the time difference changes from PM to AM

=(Format([PUSH1PRODUCTION_TIME_TUB_STOP]-[PUSH1PRODUCTION_TIME_TUB_START],"hh")*60)+Format([PUSH1PRODUCTION_TIME_TUB_STOP]-[PUSH1PRODUCTION_TIME_TUB_START],"nn")

1, start = 4:10 AM stop = 5:00 AM Total = 50.00 correct
2, start = 5:05 AM stop = 6:00 AM Total = 55.00 correct
3, start = 11:00 PM stop = 12:15 AM Total = 1365.00 incorrect :(

#3 Total should be 75.00

EDIT:

Ok this works

=IIf([Start_Time]<[Stop_Time],DateDiff("n",[Start_Time],[Stop_Time]),1440-DateDiff("n",[Stop_Time],[Start_Time]))

1440 = 24hrs * 60min
So if the time difference overlapps 12 midnight then I subtract 1440 minutes (24 hours)
You can change "n" to "h" if you only want to track hours
 
Last edited:
Hi -

Code:
Source: [url]http://www.mvps.org/access/datetime/date0004.htm[/url]
'from the debug (immediate) window:

starttime = #11:00 PM#
Endtime = #12:15 AM#
? Format(StartTime -1 -EndTime, "Short Time")
01:15

Bob
 

Users who are viewing this thread

Back
Top Bottom