Displaying specific dates

Print
Category: Date and Time Date and Time
Last Updated: 31 August 2011 31 August 2011

Displaying specific dates

To display specific dates, you can use the DateSerial() function to manipulate the day, month, and year portions of a date.

The syntax for the DateSerial function is:

DateSerial( year, month, day )

year is a numeric value between 100 and 9999 that represents the year value of the date.

month is a numeric value that represents the month value of the date.

day is a numeric value that represents the day value of the date.

TRICK: By setting the day value to zero it will return the date that is the last day of the previous month .

Example Date calculations:

Examples in a query:

1) In a query you could use this criteria to get all the records with a date in the current month:

Where [MyDateField] Between   DateSerial(Year(Date()), Month(Date()), 1) and DateSerial(Year(Date()), Month(Date()) + 1, 0)

2) In a query you could use this criteria to get all the records with a date from the previous month:

Where [MyDateField] Between    DateSerial(Year(Date()), Month(Date())-1,1) and  DateSerial(Year(Date()), Month(Date()),0)