XML RSS
What is this?
Add to My Yahoo!
Add to My MSN
Add to Google

Home
Whats New!
Need a database?
Tips via email
Learn VBA
Questions Answered
Access Tips Index


Calculating Time Interval in Minutes

To calculate time interval in minutes; i.e. the difference between two times. For example if you have created Date/Time fields with medium time format. Then you entered 10:00 AM and 12:10 PM, how would you write code that calculates this interval in minutes.  To do this you would use the DateDiff function.

 

If you were to use this in VBA code; an example may look like the following:

 

Public Sub sTimeInMinutes(Later As Date, NowTime As Date)

Dim TimeIntervalInMinutes As Long

TimeIntervalInMinutes = (DateDiff("n", Later, NowTime))

MsgBox TimeIntervalInMinutes

End Sub

If you wished to work this out in a query – then using a blank column, in the first row you would type the following:

 

TimeIntervalInMinutes: (DateDiff("n",[StartTime],[EndTime]))

 

Where StartTime and EndTime are the names of the fields that contains this information.

 

Or you may wish to do it on a form or a report.  In this case you would add an unbound text box with the following syntax:

 

= (DateDiff("n",[StartTime],[EndTime]))

 

Do you like this tip? Subscribe to my free weekly Newsletter to receive tips weekly via email. Click Here to subscribe.

footer for Microsoft Access page