ASP date and Time function examples _ Application tips

Source: Internet
Author: User
Tags current time function examples numeric value time interval

Examples of date and time functions for ASP

You can use date and time functions to get dates and times in various formats

Function
Grammar
Description
Example
Now
Now () Get the current date and time of the system Dim MyVar MyVar = Now
' MyVar
Contains the current date and time.
Date
Date () Get the current date of the system Dim MyDate MyDate = Date
' MyDate
Contains the current system date.
Time
Time () Get the system Current time Dim MyTime MyTime = Time
' Returns the current system time.
Year
Year (Date) Get the year of a given date Dim MyDate, MyYear
MyDate = #October 19, 1962#

' Assign a date.
MyYear = Year(MyDate)
' MyYear
Contains 1962 .
Month
Month (Date) Get the month of a given date Dim MyVar MyVar = Month(Now)
' MyVar contains the number corresponding to the current month.
Day
Day (Date) Get the date given Dim MyDay MyDay = Day("October 19, 1962")
' Myday contains 19 .
Hour
Hour (Time) To get a given time is the first few hours Dim MyTime, MyHour
MyTime = Now MyHour = Hour(MyTime)
' MyHour
Contains a numeric value that represents the current time.
Minute
Minute (Time) To get a given time is the first few minutes Dim MyVar
MyVar = Minute(Now)
Second
Second (Time) The first few seconds to get the time to keep Dim MySec
MySec = Second(Now)
'MySec
Contains a number that represents the current second.
Weekday
Weekday (Date) Gets the integer that the given date is the day of the week, 1 means Sunday, 2 means Monday, and so forth Dim MyDate, MyWeekDay
MyDate = #October 19, 1962#

' Dispatch date
MyWeekDay = Weekday(MyDate)
'
MyWeekDay Inclusive 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: Second date or time, later than Var1
Calculate the interval of two dates or times DateDiff ("D", Date (), #1/1/2005#)
' Return from 2005 New Year's Day how much more
DateDiff ("H", Date (), #1/1/2005#)
' Return to 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: A reference to a date or time
Add to two dates or times

The following example adds one months to January 31, 95:

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) Convert to Short date format Fromatdatetime (Date (), vblongdate)
"Display in Long date format
FormatDateTime (Date,vblongdate) Convert to Long date format
FormatDateTime (Date,vbshorttime) Convert to short time format
FormatDateTime (Date,vblongtime) Convert to long time format


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.