In ASP, the datediff function describes how to add or subtract two dates.

Source: Internet
Author: User
Tags date1

Detailed description of the datediff function in ASP
Datediff Function

Description
Returns the interval between two dates.
Syntax
Datediff (interval, date1, date2 [, firstdayofweek] [, firstweekofyear])
The syntax of the datediff function includes the following parameters:

Parameter description
Interval is required. String expression used to calculate the time interval between date1 and date2. For values, see the "Settings" section.
Date1 and date2 are required. Date expression. Two dates used for calculation.
Firstdayofweek is optional. Specify the constant of the first day of the week. If not specified, the default value is Sunday. For values, see the "Settings" section.
Firstweekofyear is optional. Specifies the constant of the first week of a year. If this parameter is not specified, the default value is the week of April 1, January 1. For values, see the "Settings" section.

Set
The interval parameter can have the following values:
Set description
Yyyy
Q quarter
M month
Y number of days in a year
D
Number of days per week
WW week
H hour
M minutes
S seconds

The firstdayofweek parameter can have the following values:

Constant Value description
Vbusesystem 0 is set using the regional language (NLS) API.
Vbsunday 1 Sunday (default)
Vbmonday 2 Monday
Vbtuesday 3 Tuesday
Vbwednesday 4
Vbthursday 5 Thursday
Vbfriday 6 Friday
Vbsaturday 7 Saturday

The firstweekofyear parameter can have the following values:

Constant Value description
Vbusesystem 0 is set using the regional language (NLS) API.
Vbfirstjan1 starts from the week of July 1, January 1 (default ).
Vbfirstfourdays 2 starts from the first week of at least four days in the New Year.
Vbfirstfullweek 3 starts from the first complete week of the year.

Description
The datediff function is used to determine the number of specified time intervals between two dates. For example, you can use datediff to calculate the number of days with different dates, or the number of weeks between the day and the last day of the current year.
To calculate the number of days for date1 and date2, you can use "number of days in a year" ("Y") or "day" ("D "). When interval is "the number of days of a 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, not date1. If interval is "Week" ("ww"), the datediff function returns the number of weeks between two dates in the calendar table. Function compute the number of Sundays between date1 and date2. If date2 is Sunday, datediff calculates date2, but date1 is not calculated even if date1 is Sunday.

If date1 is later than date2, The datediff function returns a negative number.

The firstdayofweek parameter affects the calculation of the "W" and "ww" separators.

If date1 or date2 is a date text, the specified year will become a fixed part of the date. However, if date1 or date2 is included in quotation marks ("") and the year is omittedCodeWhen the expression date1 or date2 is calculated, the current year is inserted. In this way, you can writeProgramCode.

When interval is "year" ("YYYY"), although only one day is actually different from January 1, datediff returns 1, indicating that the year is different.

Related Article

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.