DateDiff, the syntax is as follows:
DateDiff (interval character, date 1, date 2 [, firstdayofweek[, FirstWeekOfYear]])
The general use of DateDiff (interval character, date 1, date 2) is sufficient.
Explain: This function returns the date or time of the interval, returns the year, the month, the day to set the interval character, such as the interval character: "yyyy" is the comparison of the year, "D" Comparison date, "M" Comparison month, if the date 1 after the date 1, then a negative number will be returned.
As an example:
<%=datediff ("D", #2008 -1-10#, #2008 -1-2#)%>
The result is: 8
How do I write a date comparison SQL statement in an Access query?
1. First when you design an access datasheet, the Date field must be: Date/time, and if the field type is character, the date will be incorrect when compared.
2. SQL Statement Example (Find records after a specified date):
Code One
SELECT * FROM table name where DateDiff ("D", Date field column name, #指定日期 #) <= 0
Code two
SELECT * FROM table name where date field column name > #指定日期 #
Notice that the specified date is surrounded by a pound sign.
How to compare dates and times in Access, using the DateDiff function