Time functions In ASP

Source: Internet
Author: User

Date function
Description: returns the current system date.
Syntax: Date

Dateadd Function
Description: return the date of the specified interval that has been added.
Syntax: dateadd (interval, number, date)
Interval: required. String expression, indicating the time interval to be added. For values, see the "Settings" section.
Number: required. Numeric expression, indicating the number of time intervals to be added. A numeric expression can be a positive number (to get the future date) or a negative number (to get the past date ).
Date: required. Variant or the text that represents the date to add interval.
The interval parameter can have the following values:
YYYY (year), Q (quarter), m (month), y (day of the year), D (day), w (day of the week), ww (week), H (hour), n (minute), S (second)
Note: The dateadd function can be used to add or subtract a specified time interval from a date. For example, you can use dateadd to start from the day 30 days later or 45 minutes later than the current day. To add a time interval in the unit of "day" To date, you can use "day of the year" ("Y") and "day" ("D ") or "number of days in a week" ("W ").
The dateadd function does not return an invalid date. In the following example, we will add a month to April January 31:
Newdate = dateadd ("M", 1, "31-Jan-95 ")
In this example, dateadd returns February 28, instead of February 31. If date is January 31, the return value is February 29, because 1996 is a leap year.
If the calculated date is before January 1, 100 AD, an error occurs.
If the number is not a long value, the first rounding is the nearest integer.

Datediff Function
Description: return the time interval between two dates.
Syntax: datediff (interval, date1, date2 [, firstdayofweek [, firstweekofyear>)
Interval: required. String expression used to calculate the time interval between date1 and date2. For values, see the "Settings" section.
Date1, date2: required. Date expression. Two dates used for calculation.
Firstdayofweek: 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: 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.
The interval parameter can have the following values:
YYYY (year), Q (quarter), m (month), y (day of the year), D (day), w (day of the week), ww (week), H (hour), n (minute), S (second)
The firstdayofweek parameter can have the following values:
(The constant values are described below)
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:
(The constant values are described below)
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 omitted Code When the expression date1 or date2 is calculated, the current year is inserted. In this way, you can write Program Code.
When interval is "year" ("YYYY"), although only one day is actually different from January 1, datediff returns 1, indicating that the year is different.

Datepart Functions
Description: return the specified part of a given date.
Syntax: datepart (interval, date [, firstdayofweek [, firstweekofyear>)
Datepart: The function syntax has the following parameters:
Interval: required. String expression, indicating the time interval to return. For values, see the "Settings" section.
Date: required. The date expression to be calculated.
Firstdayof week: Optional. Specifies the constant of the first day of a week. If not specified, the default value is Sunday. For values, see the "Settings" section.
Firstweekofyear: 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.
The interval parameter can have the following values:
YYYY (year), Q (quarter), m (month), y (day of the year), D (day), w (day of the week), ww (week), H (hour), n (minute), S (second)
The firstdayofweek parameter can have the following values:
(The constant values are described below)
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:
(The constant values are described below)
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 full week (not cross year) in the new year.
Note: The datepart function is used to calculate the date and return the specified interval. For example, datepart is used to calculate the day of a week or the current time.
The firstdayofweek parameter affects the calculation of the interval between "W" and "ww.
If date is a date text, the specified year will become a fixed part of the date. However, if date is included in quotation marks ("") and the year is omitted, the current year will be inserted every time the date expression is calculated in the code. In this way, you can write program code for different years.

dateserial function
Description: for a specified year, month, or day, a variant of the date subtype is returned.
Syntax: dateserial (year, month, day)
year: a number or numeric expression between 100 and 9999.
month: Any numeric expression.
day: Any numeric expression.
Note: to specify a date, for example, on April 9, December 31, 1991, the value range of each parameter in the dateserial function should be acceptable. The value of today should be between 1 and 31, the value of the month should be between 1 and 12. However, you can also use a numeric expression indicating the year, month, and number of days before or after a specific day to specify a relative date for each parameter.
the following example uses a numeric expression instead of an absolute date. Here, the dateserial function returns the date of 10 years (1990-10) before January 1, and one day (1-1) between two months (8-2.
dateserial (1990-10, 8-2, 1-1)
for the year parameter, if the value range is from 0 to 99, it is interpreted as 1900 to 1999. For the year parameter beyond this range, four digits are used to represent the year (for example, January 1, 1800 ).
when the value of any parameter exceeds the acceptable range, it is carried to the next large time unit as appropriate. For example, if 35 days are specified, the number of days is interpreted as a month plus the number of days. The number of days is determined by the year and month. However, if the value of the parameter exceeds the range of-32,768 to 32,767, or the date specified by the three parameters (either directly or through the expression) exceeds the acceptable date range, an error occurs.

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.