Some date-time functions in ASP

Source: Internet
Author: User
Tags current time date1 numeric numeric value time interval

This article provides a brief introduction to the VBScript Time function, which can be used for general applications and specific requirements for further searching.

Date () Get dates, format: 2004-2-28

Time () to get the date, format: 22:24:59

Now () Get date and time format: 2005-5-2 22:37:30

D=date ()

Get Year: Years (d)

Get month: month (d)

Get Days: Day (d)

Get Day of the week: weekday (d)

T=time ()

Get hours: hour (t)

Get minutes: Minute (t)

Get seconds: second (t)

Date Add function: DateAdd (interval, number, date)

You can use this function to add or subtract a specified time interval from a date.

Parameter description:

Base interval for interval-operations

number-Plus how many, can be negative

date-Base Date

Here is an optional value for interval, note with quotes:

Set description

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

N Minutes

s seconds

Example:

1. Calculate Tomorrow:

Tomorrow=dateadd ("D", 1,date ())

2, the day before December 1, 2012:

Preday=dateadd ("D",-1, "2012-12-1")

Please search for more detailed usage.

Date interval function-datediff (interval, date1, date2[, firstdayofweek][, FirstWeekOfYear])

Calculates the gap between two dates.

For example, you can use DateDiff to calculate the number of days between two dates, or to calculate how many weeks from today to the end of the year. If the date1 is later than Date2, a negative number is returned.

Parameter description:

interval-with DATEADD () function

Date1,date2-Two dates for operations

Optional Parameters:

firstdayofweek-specifies a constant for the first day of the one week. If not specified, Sunday is the first day.

This parameter affects the result when the two-date difference is calculated several weeks (the time interval symbol "W" or "ww"). Please search for specific.

firstweekofyear-specifies how the first week of the year is determined and, if not specified, the first week of the week containing January 1. Please search for specific.

Other functions:

DateSerial (year, month, day)-converts numeric values to date variables and returns the same value type as the date () function. For example, if day=35, the next month is automatically calculated. For example, DateSerial (1990-10, 8-2, 1-1) calculates the date before the 10 year, 2 month, and day of August 1, 1990, which is May 31, 1980.

DatePart (interval, date[,firstdayofweek[, firstweekofyear])-Returns the numeric value of the specified time section. For example, you can use DatePart to calculate the day of the week or the current clock. Parameters are the same as above.

DateValue (date)-converts various date format strings to date variables and returns the same value type as the date () function. For example, in addition to the 12/30/1991 and 12/30/91, DateValue also identified December 30, 1991 and Dec 30, 1991.

TimeValue-Converts various time format strings into time variables. Principle with DateValue.

TimeSerial (hour, minute, second)-Converts a numeric value to a time variable, and returns the same value type as the Times () function. Principle with dateserial.

Timer ()-The number of seconds from midnight to the current elapsed time.

Now () gets the current date and time of the system Dim MyVar MyVar = Today

MyVar contains the current date and time.

Date date () Gets the system's current date Dim mydate mydate = Date

MyDate contains the current system date.

Time times () to get the system's current mytime Dim mytime = Hour

Returns the current system time.

Year years (date) Gets the vintage of the given date Dim mydate, myyear

MyDate = #October 19, 1962#

An example of the function syntax

Now () gets the current date and time of the system Dim MyVar MyVar = Today

MyVar contains the current date and time.

Date date () Gets the system's current date Dim mydate mydate = Date

MyDate contains the current system date.

Time times () to get the system's current mytime Dim mytime = Hour

Returns the current system time.

Year years (date) Gets the vintage of the given date Dim mydate, myyear

MyDate = #October 19, 1962#

Assign a date.

Myyear = year (mydate)

Myyear contains 1962.

Month Month (date) Gets the month Dim MyVar MyVar = Month (now) for the given date

MyVar contains the number corresponding to the current month.

Day (date) Gets the number of the given date Dim myday myday = Days ("October 19, 1962")

Myday contains 19.

Hour Hour (time) Gets the first few hours of Dim MyTime, Myhour

MyTime = Now Myhour = Hour (mytime)

Myhour contains values that represent the current time.

Minute Minute (time) Gets the first few minutes of Dim MyVar

MyVar = Minute (now)

Second Second (Time) is the first few seconds Dim mysec

Mysec = Second (now)

Mysec contains the number representing the current second.

Weekday Weekday (date) Gets the integer for the given date of the week, 1 for Sunday, 2 for Monday, and so on Dim mydate, Myweekday

MyDate = #October 19, 1962#

Dispatch Date

Myweekday = Weekday (mydate)

Myweekday contains 6,mydate representative Friday

DateDiff DateDiff ("Var", VAR1,VAR2)

Var: Date or time interval factor with the following parameters:

YYYY m month D Day WW Week H S SEC Var1: first date or time

VAR2: The second date or time, which calculates the interval of two dates or times Var1 late DateDiff ("D", date (), #1/1/2005#)

Return from 2005 New Year's Day how much more

DateDiff ("H", Date (), #1/1/2005#)

Return from 2005 New Year's Day and how many hours

DateDiff ("D", #1/1/2003#, #1/1/2005#)

Returns the number of days between two dates

DateAdd DateDiff ("Var", VAR1,VAR2)

Var: Date or time interval factor:

VAR1: Date or time interval multiple

VAR2: Date or time of reference to two dates or times add the following example adds one months to January 31, 95:

Newdate = DateAdd ("M", 1, "31-jan-95")

In this example, DATEADD returns February 28, 95, not February 31, 95. If date is January 31, 96, it returns February 29, 96, because 1996 is a leap year.

If the calculated date is before 100 A.D., an error is generated.

FormatDateTime FormatDateTime (date,vbshortdate) into Short date format fromatdatetime (date (), vblongdate)

"Display in Long date format

FormatDateTime (date,vblongdate) into a long date format

FormatDateTime (Date,vbshorttime) into a short time format

FormatDateTime (Date,vblongtime) into a long time lattice

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.