DateDiff function of the solution

Source: Internet
Author: User
Tags date constant date1 expression numeric time interval
function DateDiff function

Describe
Returns the time interval between two dates.
Grammar
DateDiff (interval, date1, date2 [, firstdayofweek][, FirstWeekOfYear]])
The syntax for the DATEDIFF function has the following parameters:

Parameter description
Interval must be selected. A string expression that is used to calculate the time interval between Date1 and Date2. For numeric values, see the "Settings" section.
Date1, Date2 must choose. An expression of a date. Two dates used for the calculation.
FirstDayOfWeek Optional. Specifies the constant for the first day of the week. If not specified, the default is Sunday. For numeric values, see the "Settings" section.
FirstWeekOfYear Optional. Specifies a constant for the first week of the year. If not specified, the default is the week of January 1. For numeric values, see the "Settings" section.


Set up
The interval parameter can have the following values:
Set description
YYYY years
Q Quarter
M month
Y number of days in a year
D-Day
W Number of days in a week
WW Week
H hours
M minutes
s seconds


The FirstDayOfWeek parameter can have the following values:

Constant numerical description
Vbusesystem 0 uses the regional language Support (NLS) API settings.
Vbsunday 1 week day (default)
Vbmonday 2 weeks A
Vbtuesday 3 week Two
Vbwednesday 4 week Three
Vbthursday 5 week Four
Vbfriday 6 Friday
Vbsaturday 7 Saturday


The FirstWeekOfYear parameter can have the following values:

Constant numerical description
Vbusesystem 0 uses the regional language Support (NLS) API settings.
VbFirstJan1 1 begins on the week of January 1 (default).
vbFirstFourDays 2 begins with the first week of at least four days in the new year.
Vbfirstfullweek 3 begins with the first full week of the new Year.


Description
The DateDiff function is used to determine the number of specified time intervals that exist between two dates. For example, you can use DateDiff to calculate the number of days between two date differences, or the day to the last day of the year.
To calculate the number of days between Date1 and Date2, you can use "Days of the Year" ("Y") or "Day" ("D"). When interval is the number of days of the Week ("W"), DateDiff returns the number of weeks between two dates. If the date1 is Monday, then DateDiff calculates the number of Monday before Date2. This result contains date2 and does not contain date1. If interval is "Week" ("WW"), the DateDiff function returns the number of weeks between two dates in the Calendar table. function calculates the number of Sunday between Date1 and Date2. If the date2 is Sunday, DateDiff will calculate the date2, but even if Date1 is Sunday, it will not calculate date1.

If Date1 is later than Date2, the DateDiff function returns a negative number.

The FirstDayOfWeek parameter affects computations that use the "w" and "ww" interval symbols.

If Date1 or date2 is a date literal, the specified year becomes a fixed part of the date. However, if the Date1 or date2 is included in quotation marks ("") and the year is omitted, the current year is inserted each time the Date1 or date2 expression is evaluated in the code. This allows you to write program code that works for different years.

When interval is "year" ("yyyy"), comparing the January 1 of December 31 and the following year, although the actual difference is only one day, DateDiff returns 1 to indicate a difference of a year.



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.