Asp: DateDiff function, aspdatediff Function

Source: Internet
Author: User
Tags date1

Asp: DateDiff function, aspdatediff Function

DateDiff Function

Returns the value of Variant (Long), indicating the number of time intervals between two specified days.

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

The DateDiff function syntax contains the following naming parameters:

Part of description interval is required. String expression used to calculate the time difference between date1 and date2

Date1 □date2 is required; Variant (Date ). The two dates used in the calculation.

Firstdayofweek is optional. Specifies the constant of the first day of a week. If not specified, Sunday is the first day.

Firstweekofyear is optional. Specifies the constant of the first week of a year. If this parameter is not specified, the week that contains April 1 is the first week.

 

Set the value of interval as follows: (set description)

Yyyy

Q quarter

M month

Y number of days in a year

D

Number of days per week

Ww week

H hour

N minutes

S seconds

 

The firstdayofweek parameter is set as follows: (constant value description)

VbUseSystem 0 is set using nls api.

VbSunday 1 Sunday (default)

VbMonday 2 Monday

VbTuesday 3 Tuesday

VbWednesday 4

VbThursday 5 Thursday

VbFriday 6 Friday

VbSaturday 7 Saturday

 

Constant Value description

VbUseSystem 0 is set using nls api.

VbFirstJan1 1 starts from the week of July 1, January 1 (default ).

VbFirstFourDays 2 starts from the first half of its week in the week of the New Year.

VbFirstFullWeek 3 starts from the week of the first non-Cross-Year Plan.

 

Note:

The DateDiff function can be used to determine the specified time interval between two dates. For example, you can use DateDiff to calculate the number of days between two dates, or calculate the number of weeks from today to the end of the year. To calculate the number of days in which date1 differs from date2, you can use "day of the year" (y) or "day" (d ). When interval is "the number of days in a week" (w), DateDiff returns the number of weeks in the two-day period. If date1 is Monday, DateDiff calculates the number of Monday until date2. This number contains date2 but not date1. However, if interval is "Week" (ww), The DateDiff function returns the "calendar week" number for the two-day period. Calculated based on the number of Sundays between date1 and date2. If date2 is just Sunday, date2 will also be added to the DateDiff counting result. However, no matter whether date1 is Sunday or not, it will not be included. If date1 is later than date2, the return value of the DateDiff function is negative. The firstdayofweek parameter affects the calculation result using the time interval symbol "W" or "WW. If date1 or date2 is a date text, the specified year becomes a fixed part of the date. However, if date1 or date2 is enclosed by double quotation marks ("") and the year is omitted, the current year will be inserted into the code each time the expression date1 or date2 is calculated. In this way, you can write the program code for different years. When calculating the year difference between December 31 and January 1 in the next year, DateDiff returns 1, indicating that the year is different, although only one day is actually 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.