Hi, I have a query where I have 2 date/time fields [DepartTime] and [ArrivalTime]. I want to calculate the time spend on the road can I do this with this type of data field or do I have to define them as number data types?
A quick search of Access Help for DateDiff returns:
[tt] Calculate the difference between two date or time values
The following table lists examples of expressions that use the DateDiff function to calculate the difference between any two date and time values.
You can use these expressions in calculated controls (calculated control: A control that is used on a form, report, or data access page to display the result of an expression. The result is recalculated each time there is a change in any of the values on which the expression is based.) on forms, reports, and data access pages (data access page: A Web page, published from Access, that has a connection to a database. In a data access page, you can view, add to, edit, and manipulate the data stored in the database. A page can also include data from other sources, such as Excel.).
Expression Description
=DateDiff("d", [OrderDate], [ShippedDate]) Displays the variance in days between the values of the OrderDate and ShippedDate fields.
=DateDiff("yyyy", [Birthday1], [Birthday2]) Displays the variance in years between the values of the Birthday1 and Birthday2 fields.
=DateDiff("m", #12/24/2000#, #11/26/2000#) Displays the variance in months between the two dates. The expression evaluates to -1, since the first date falls after the second date.
=DateDiff("yyyy", #12/31/2000#, #1/1/2001#) Displays the variance in years between the two dates. The expression evaluates to 1, even though only a day has elapsed.
You can use these expressions in a calculated field in a query.
Expression Description
LagTime: DateDiff("d", [OrderDate], [ShippedDate]) Displays in the LagTime field the number of days between the values of the OrderDate and ShippedDate fields.
YearsLapsed: DateDiff("yyyy", #12/31/2000#, #1/1/2001#) Displays in the YearsLapsed field the number of years between the two dates.
[/tt]
It also includes the "See Also" section with the following topics:
Add to or subtract from date and time values
Calculate the serial number of the day, week, or month in a date
Combine text, number, date, and time values
Extract a part of a date or time value
Format date and time values
Use current date and time in calculations
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.