ASP Date and Time Function example

Source: Internet
Author: User

ASP Date and Time Function example

You can use the date and time functions to obtain the date and time in various formats.

Function Syntax Description Example
Now Now () Obtain the current date and time of the system. Dim myvar =Now
'Myvar
Contains the current date and time.
Date Date () Obtain the current system date Dim mydate =Date
'Mydate'
Contains the current system date.
Time Time () Obtain the current system time Dim mytime =Time
'Returns the current system time.
Year Year (date) Get the year of a given date Dim mydate, myyear
Mydate = # October 19,196 2 #

'Assign a date.
Myyear =Year (Mydate)
'Myyear'
Include1962.
Month Month (date) Returns the month of a given date. Dim myvar =Month (Now)
'Myvar contains the number corresponding to the current month.
Day Day (date) Returns the number of the given date. Dim myday =Day ("October 19,196 2")
'Myday' includes19.
Hour Hour (time) The hour at which the given time is obtained Dim mytime, myhour
Mytime = now myhour =Hour (Mytime)
'Myhour
Contains the value representing the current time.
Minute Minute (time) Returns the number of minutes for a given time. Dim myvar
Myvar =Minute (Now)
Second Second (time) The number of seconds to obtain the token. Dim mysec
Mysec =Second (Now)
'Mysec
Contains the number representing the current second.
Weekday Weekday (date) Returns the integer of the given date in the day of the week. 1 indicates Sunday, 2 indicates Monday, and so on. Dim mydate, myweekday
Mydate = # October 19,196 2 #

'Dispatch date
Myweekday =Weekday (Mydate)
'
MyweekdayInclude6. mydateFriday
Datediff Datediff ("Var", var1, var2)
VaR: date or interval factor, which has the following parameters:
Yyyy, M, D, WW, week, H, S, seconds

Var1: the first date or time
Var2: second date or time, later than var1

Calculate the interval between two dates or times Datediff ("D", date (), #1/1/2005 #)
'Return the number of New Year's Eve before 2005
Datediff ("H", date (), #1/1/2005 #)
'How many hours are there before 2005 New Year's Day?
Datediff ("D", #1/1/2003 #, #1/1/2005 #)
'Returns the number of days between two dates.
Dateadd Datediff ("Var", var1, var2)
VaR: date or interval factor:
Var1: date or interval multiple
Var2: benchmark of date or time
Add two dates or times

In the following example, we will add a month to April January 31:

Newdate =Dateadd ("M",1,"31-Jan-95")

In this example,DateaddReturn February 28, instead of February 31. IfDateIf the value is January 31, the return value is February 29, because 1996 is a leap year.

If the calculation date is before January 1, 100 AD, an error occurs.

Formatdatetime Formatdatetime (date, vb1_date) Convert to short Date Format Fromatdatetime (date (), vblongdate)
"Displayed in long Date Format
Formatdatetime (date, vblongdate) Convert to long Date Format
Formatdatetime (date, vb1_time) Convert to short time format
Formatdatetime (date, vblongtime) Convert to long time format

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.