How to compare dates and times in Access, using the DateDiff function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.