Using MS Access/Time fields

Advertisement


Question
If I have two time fields, FromTime and ToTime. How do i calculate the difference between the two times?

Answer
Access stores date/time values as a double precision number where the integer portion is the number of days since 12/30/1899 and the decimal portion is a fraction of a day (ex: 6AM or 6 hrs = .25)

So if the fields contain just time values you could just subtract them:

[ToTime]-[FromTime]

However, if the time spans past midnight or more than 1 day, then that is going to be inaccurate. Its better to use the DateDiff function and count the minutes (or seconds) between the 2 times and then cacluates the hours (or hours and minutes).

Hope this helps,
Scott<>
Microsoft Access MVP 2007
Author: MS Office Access 2007 VBA

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 15 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

©2012 About.com, a part of The New York Times Company. All rights reserved.