Date Calculations in Access

There are a number of ways to calculate the time between two dates in Access. You can use a calculated field in a query, a calculated control in a form or report, or you can use a VBA procedure to perform the calculation.

If you need to calculate the number of days between two dates, the syntax is:

=[One date field] - [Another date field]

You can use functions to calculate the number of years between two dates:

=Year([One date field]) - Year([Another date field])

You can also use the DateDiff() function, which uses an argument to determine how the time interval is measured.

For example,

=DateDiff("q", Date1, Date2)

returns the number of quarters between the two fields. (In the example above, Date1 would be subtracted from Date2.) The other intervals that can be used in this expression are as follows: “yyyy” – Years, “m” – Months, “y” – Day of Year, “d” – Day, “w” – Weekdays, “ww” – Weeks, “h” – Hours, “n” – Minutes, “s” – Seconds.

Naming Date Fields

When naming date fields in Access, avoid naming a field Date, since this is a built-in Access function. Instead, consider using more descriptive names, such as BeginDate, HireDate, etc.

Hard Coding a Date

When calculating with dates in Access, you can hard-code an arbitrary date by using the following syntax:

#mm/dd/yyyy#

For example, you would use the following code to subtract a date from Jan. 1, 2006:

=#1/1/2006# - [Date Field]

Tag Search:
Comments: Leave a Comment

Leave a Reply