[Reprinted] Time Operation statements in SQL Access

Source: Internet
Author: User
Source post address click open link ACCESS statement: select * from data table where (DateDiff (d, Date Field, Date () 0) syntax DateDiff (interval, date1, date2 [, firstdayofweek] [, firstweekofyear]) the syntax of the DateDiff function contains the following parameters: operation, event, method, and attribute

Source post address click open link ACCESS statement: select * from data table where (DateDiff ('D', Date Field, Date () = 0) syntax DateDiff (interval, date1, date2 [, firstdayofweek] [, firstweekofyear]) the syntax of the DateDiff function contains the following parameters: operation, event, method, and attribute

Original post address click open link


ACCESSStatement:

Select * from data table where (DateDiff ('D', Date Field, Date () = 0)

Syntax

DateDiff (interval, date1, date2 [, firstdayofweek] [, firstweekofyear])

The syntax of the DateDiff function includes the following parameters:Operation, Event, method, attribute, function, or process provides information values .) :

Parameters Description
Interval Required. This expression is used to calculate the difference between date1 and date2.TimeInterval.
Date1, date2 Required. Variable type (date type ). Two dates to be used for calculation.
Firstdayofweek Optional. Constant, specifies the first day of a week. If not specified, the default value is Sunday.
Firstweekofyear Optional. A constant that specifies the first week of a year. If this parameter is not specified, the first week is the week of July 22, January 1 by default.

Set

Interval includes the following settings:

Set Description
Yyyy Year
Q Quarter
M Month
Y One day of a year
D Days
W Workday
Ww Week
H Hour
N Minute
S Seconds

The firstdayofweek parameter includes the following settings:

Constant Value Description
VbUseSystem 0 Use nls api settings.
VbSunday 1 Sunday (default)
VbMonday 2 Monday
VbTuesday 3 Tuesday
VbWednesday 4 Wednesday
VbThursday 5 Thursday
VbFriday 6 Friday
VbSaturday 7 Saturday

Constant Value Description
VbUseSystem 0 Use nls api settings.
VbFirstJan1 1 It starts from the week where January 1, January 1 (default ).
VbFirstFourDays 2 Start from the first week of at least four days of the new year.
VbFirstFullWeek 3 From the first full week of the year.

Annotation

You can use the DateDiff function to determine the number of specified datesTimeInterval. For example, you can use DateDiff to calculate the number of days between two dates or the number of weeks between today and the end of the year.

To calculate the number of days between date1 and date2, you can use "one day of a year" ("y") or "day" ("d "). When interval is "workday" ("w"), DateDiff returns the number of weeks between two dates. If date1 is Monday, DateDiff calculates the number of Monday before date2. Date2 is included, but date1 is not included. However, if interval is "Week" ("ww"), the DateDiff function returns the number of calendar weeks between two dates. It calculates the number of Sundays between date1 and date2. If date2 is Sunday, DateDiff will include it, but it will not be included even if date1 is Sunday.

If date1 referencesTimePoint, then the DateDiff function returns a negative number.

The firstdayofweek parameter affects the calculation of the interval between "w" and "ww.

If date1 or date2 is a date text (date text: any character sequence with a valid format, both sides are enclosed by the number symbol. Valid formats include the specified date format or common date format set by the Code region .), The specified annual meeting becomes the permanent part of the date. However, if date1 or date2 is enclosed in double quotation marks ("") and the year is omitted, the current year is inserted into the code each time date1 or date2 expressions are calculated. In this way, you can write code for different years.

When we compare January 1, December 31 with January 1, January 1, for "yyyy", DateDiff returns 1 even if only one day is used.

Note: For date1 and date2, if the Calendar attribute is set to the Gregorian Calendar, the provided date must be the Gregorian Calendar. If the calendar is a calendar, the provided date must be a calendar.

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.