DateDiff Database Time difference function

Source: Internet
Author: User
Tags date1

Describe
returns a time interval between two dates.
Grammar
DateDiff ( interval , Date1 Date2[ , FirstDayOfWeek[ , FirstWeekOfYear]] )

The syntax for the DateDiff function has the following parameters:

Parameters Describe
Interval Must be selected. A string expression that is used to calculate the time interval between date1 and date2 . See the Settings section for values.
Date1, Date2 Must be selected. The date expression. The two dates used for the calculation.
FirstDayOfWeek Optional. Constant that specifies the first day of the week. If not specified, the default is Sunday. See the Settings section for values.
FirstWeekOfYear Optional. A constant that specifies the first week of the year. If not specified, the default is the week in which January 1 is located. See the Settings section for values.
Set up
intervalParameters can have the following values:
Set up Describe
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 Value Describe
Vbusesystem 0 Use the regional language Support (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

The firstweekofyear parameter can have the following values:

Constant Value Describe
Vbusesystem 0 Use the regional language Support (NLS) API settings.
VbFirstJan1 1 Starting from the week of January 1 (default).
vbFirstFourDays 2 Starting from the first week of at least four days in the new year.
Vbfirstfullweek 3 Start with the first full week in the new year.
Description
DateDiffThe function is used to determine the number of specified time intervals that exist between two dates. For example, you can use DateDiffCalculates the number of days between two dates, or the day of the week between the last day of the current year.

To calculate the number of days between date1 and date2 , you can use the days of the year ("Y") or the "Day" ("D"). When interval is "Days of the Week" ("W"),DateDiff Returns the number of weeks between two dates. If date1 is Monday, 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. The function calculates the number of Sunday between date1 and date2 . If date2 is Sunday,DateDiff calculates date2, but even if date1 is Sunday, date1is not counted.

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

The firstdayofweek parameter has an effect on the calculations 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 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 applies to different years.

When the interval is "year" ("yyyy"), compare December 31 and the next year January 1, although actually only one day,DateDiff returns 1 indicates a difference of one year.

DateDiff Database Time difference 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.