ASP Date and Time Function example

Source: Internet
Author: User

Function syntax example
Now now () Get the current date and time of the system dim myvar = now
''Myvar contains the current date and time.
Date () gets the current system date dim mydate = Date
''Mydate contains the current system date.
Time () gets the current system time dim mytime = Time
''Returns the current system time.
Year Year (date) gets the year dim mydate, myyear of the given date
Mydate = # October 19,196 2 #
''Assign a date.
Myyear = year (mydate)
''Myyear contains 1962.
Month (date) gets the month dim myvar = month (now) of the given date)
''Myvar contains the number corresponding to the current month.
Day (date) returns the number of the given date dim myday = Day ("October 19,196 2 ")
''Myday contains 19.
Hour hour (time) gets the hour dim mytime, myhour
Mytime = now myhour = hour (mytime)
''Myhour contains the value representing the current time.
Minute (time) gets the number of minutes dim myvar
Myvar = minute (now)
Second second (time) is the number of seconds dim mysec
Mysec = second (now)
''Mysec contains the number representing the current second.
Weekday weekday (date) gets 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)
''Myweekday contains 6, and mydate represents Friday
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: The second date or time, which is later than var1 to calculate the interval of two dates or times datediff ("D", date (), #1/1/2005 #)
''Returns the number of New Year's Day 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: Add two dates or times as the date or time benchmark. The following example adds January 31 to the previous month:

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 calculation date is before January 1, 100 AD, an error occurs.

Formatdatetime (date, vb1_date) to short date format fromatdatetime (date (), vblongdate)
"Displayed in long Date Format
Formatdatetime (date, vblongdate) to long Date Format
Formatdatetime (date, vb1_time) is converted to the short time format
Formatdatetime (date, vblongtime) is converted to a 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.