Detailed ASP time functions, ASP time functions, ASP week functions, and ASP now functions

Source: Internet
Author: User
Tags date1 month name

Now () gets the current system Date and Time. asp output can be written as follows: <% = now () %>

Year (now () gets the year, ASP output: <% = year (now () %>

Month (now () gets the current month, ASP output: <% = month (now () %>

When day (now () is obtained, ASP outputs: <% = Day (now () %>

Minute (now () gets the number of minutes, ASP output: <% = minute (now () %>

Second (now () obtains the number of seconds. asp outputs: <% = second (now () %>

Date () gets the current system date in the format of 2004-2-28

Time () gets the current system time in the format of 22: 24: 59

 
Take 22:37:30 Monday as an example:

2005-5-2: <% = Date () %>
2005: <% = year (date () %>
5: <% = month (date () %>
2: <% = Day (date () %>

22: <% = hour (now () %>
37: <% = minute (now () %>
30: <% = second (now () %>

Monday: <% = weekdayname (weekday (now) %>

 

ASP Time Functions
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, the current year will be inserted every time date1 or date2 expressions are calculated in the code. In this way, you can write program code for different years.
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 Functions
Description: returns the variant of the date subtype for the specified year, month, and day.
Syntax: dateserial (year, month, day)
Year: a numeric or numeric expression between 100 and 9999.
Month: Any numeric expression.
Day: Any numeric expression.
Note: You need to specify a date. For example, the value range of each parameter in the dateserial function on January 1, December 31, 1991 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.

Datevalue Function
Description: returns the variant of the date subtype.
Syntax: datevalue (date)
The date parameter must be a string expression that represents a date from January 1, January 1-9, 100 to January 1, December 31, 999. However, date can also be any expression that represents the combination of date, time, or date and time in the preceding range.
Note: If the date parameter contains time information, datevalue does not return time information. However, if the date contains invalid time information (such as "89: 98"), an error occurs.
If date is a string that only contains numbers separated by valid date delimiters, datevalue identifies the order of months, days, and years based on the short date format specified for the system. Datevalue also identifies a specific date that contains the month name (whether it is the full name or abbreviation. For example, in addition to being able to recognize 12/30/1991 and 12/30/91, datevalue can also recognize December 30,199 1 and Dec 30,199 1.
If the year of date is omitted, datevalue uses the current year of the computer system date.

Day function
Description: return an integer (including 1 and 31) between 1 and 31, representing the day of a month.
Syntax: Day (date)
The date parameter is any expression that can represent a date. If the date parameter contains null, null is returned.

Formatdatetime Function
Description: Return expression, which has been formatted as a date or time.
Syntax: formatdatetime (date [, namedformat])
Date: required. The date expression to be formatted.
Namedformat: Optional. Indicates the value of the date/time format used. If it is omitted, vbgeneraldate is used.
The namedformat parameter can have the following values:
(The constant values are described below)
Vbgeneraldate 0 displays the date and/or time. If there is a date part, it is displayed as the short date format. If there is a time part, it is displayed as a long time format. If all exist, all parts are displayed.
Vblongdate 1 displays the date in the long date format specified in the computer region settings.
Vb1_date 2 displays the date in the short date format specified in the computer region settings.
Vblongtime 3 displays the time in the specified time format in the computer region settings.
Vb1_time 4 uses the 24-hour format (HH: mm) to display the time.

Hour Function
Description: return an integer between 0 and 23 (including 0 and 23), representing an hour in a day.
Syntax: hour (time)
The time parameter is any expression that can represent time. If the time parameter contains null, null is returned.

Minute Function
Description: return an integer (including 0 and 59) between 0 and 59, representing a minute in an hour.
Syntax: minute (time)
The time parameter is any expression that can represent time. If the time parameter contains null, null is returned.

Month Function
Description: returns an integer (including 1 and 12) between 1 and 12, representing a month in a year.
Syntax: Month (date)
The date parameter is any expression that can represent a date. If the date parameter contains null, null is returned.

Monthname Function
Description: return a string indicating the specified month.
Syntax: monthname (month [, abbreviate])
Month: required. The numeric value of a month. For example, January is 1, February is 2, and so on.
Abbreviate: Optional. Boolean value, indicating whether the month name is abbreviated. If this parameter is omitted, the default value is false, indicating that the month name is not abbreviated.

Now Function
Description: returns the current date and time value based on the date and time set by the computer system.
Syntax: Now

Second Function
Description: return an integer (including 1 and 59) between 0 and 59, representing a second in a minute.
Syntax: Second (time)
The time parameter is any expression that can represent time. If the time parameter contains null, null is returned.

Time Function
Description: returns the date sub-type variant, indicating the current system time.
Syntax: Time

Timeserial Function
Description: returns a date sub-type variant, which contains the Time of the timer, minute, and second.
Syntax: timeserial (hour, minute, second)
Hour: A value from 0 (a.m.) to 23 (p.m.
Minute: Any numeric expression.
Second: Any numeric expression.
Note: To specify a time point, such as 11:59:59, The timeserial parameter value should be within the acceptable range; that is, the hour should be between 0-23, the minute and second must be between 0 and 59. However, you can use a numeric expression to specify the relative time for each parameter. This expression represents the time, minute, or second before or after a time. In the following example, an expression is used to replace the absolute time. The timeserial function returns the time (-15) of the six hours (12-6) before noon, that is, 5:45:00 a.m ..
Timeserial (12-6,-15, 0)
When the value of any parameter exceeds the acceptable range, it is correctly carried to the next large time unit. For example, if 75 minutes are specified, the time is interpreted as one hour and 15 minutes. However, if any parameter value exceeds the range of-32768 to 32767, an error occurs. If the time specified by the three parameters or the time calculated by the expression exceeds the acceptable date range, an error occurs.

Timevalue Function
Description: returns the variant of the date subtype containing the time.
Syntax: timevalue (time)
The time parameter usually represents a string expression (including 0:00:00 and 12:00:00) from 23:59:59 (11:59:59 a.m.) to 0:00:00 (23:59:59 p.m ). However, time can also be an expression that represents any time in the range. If the time parameter contains null, null is returned.
Note: The time can be input in 12 or 24-hour clock format. For example, "PM" and "" are both valid time parameters.
If the time parameter contains date information, the timevalue function does not return date information. However, if the time parameter contains invalid date information, an error occurs.

Weekday Function
Description: return an integer representing the day of a week.
Syntax: weekday (date, [firstdayofweek])
Date: Any expression that represents a date. If the date parameter contains null, null is returned.
Firstdayofweek: constant of the first day of the week. If this parameter is omitted, vbsunday is used by default.
The firstdayofweek parameter has the following settings:
(The constant values are described below)
Vbusesystem 0 is set using the regional language (NLS) API.
Vbsunday 1 Sunday
Vbmonday 2 Monday
Vbtuesday 3 Tuesday
Vbwednesday 4
Vbthursday 5 Thursday
Vbfriday 6 Friday
Vbsaturday 7 Saturday
The weekday function returns the following values:
(The constant values are described below)
Vbsunday 1 Sunday
Vbmonday 2 Monday
Vbtuesday 3 Tuesday
Vbwednesday 4
Vbthursday 5 Thursday
Vbfriday 6 Friday
Vbsaturday 7 Saturday

Weekdayname Function
Description: returns a string that indicates the specified day of the week.
Syntax: weekdayname (weekday, abbreviate, firstdayofweek)
Weekday: required. The value of a day in a week. The value definition for each day depends on the firstdayofweek parameter settings.
Abbreviate: Optional. Boolean value, indicating whether the abbreviation represents the name of each day of the week. If this parameter is omitted, the default value is false.
Firstdayofweek: Optional. Specifies the value of the first day of the week. For the value, see the "Settings" section.
The firstdayofweek parameter has 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

Year Function
Description: returns an integer representing a year.
Syntax: Year (date)
The date parameter is any parameter that can represent the date. If the date parameter contains null, null is returned.

Datediff ("N", cdate (""), cdate "))
Here, the first parameter is the time interval, and "N" indicates minutes. You can also use other units. The minimum unit is second.
You can use the datediff () function. For example:
Datediff ("D", begindate, enddate ).
The datediff function actually uses begindate-enddate. If enddate> begindate, datediff returns a negative number. Datediff can calculate the time difference by day, hour, and other units.

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.