Several ASP + operation date functions

Source: Internet
Author: User
I. Operations for time addition and subtraction
Subtract a certain number of days from the interval
Function date1 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Newtime = newtime. Format ("mm/DD/YYYY", datetimeformatinfo)
Response. Write (newtime)
End Function

Use the method of adding negative days minus a certain number of days
Public Function date2 ()
Dim newtime as datetime
Newtime = datetime. Now. adddays (-7)
Dim s as string = newtime
Return s
End Function

Returns the date name string.
Function date3 ()
Dim newtime as datetime = now. adddays (-7)
Response. Write (system. String. Format ("{0: mm/DD/YYYY}", newtime ))
End Function

Function date4 ()
Dim newtime as datetime
Newtime = now. adddays (-7)
Return newtime. tostring ()
End Function

Long time mode
Public Function date5 ()
Dim newtime as datetime
Newtime = now ()
Return newtime. tolongtimestring ()
End Function

Use short time mode
Public Function date6 ()
Dim newtime as datetime
Newtime = now ()
Return newtime. tow.timestring ()
End Function

Use long date mode
Public Function date7 ()
Dim newtime as datetime
Newtime = now ()
Return newtime. tolongdatestring ()
End Function

Use short-day start Mode
Public Function date8 ()
Dim newtime as datetime
Newtime = now ()
Return newtime. tow.datestring ()
End Function

Format date functions

Format to common format
Function date9 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 0)
End Function

Format the growth Date Format
Function date10 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 1)
End Function

Format to short Date Format
Function date11 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 2)
End Function

Format the growth time format
Function date12 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 3)
End Function

Format to Short-Time Format
Function date13 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 4)
End Function

Displays the year, month, and day of the time separately.

Display date
Function date14 ()
Dim newtime as datetime = now. adddays (-7)
Dim s as string
S = (system. String. Format ("{0: dddd}", newtime ))
Return s
End Function

Returns the day of the week of the date.
Function date15 ()
Dim mydate as datetime
Dim myweekday as integer
Mydate = now. adddays (-5)
Myweekday = weekday (mydate)
Return myweekday
End Function

Returns the month value.
Function date16 ()
Dim mydate as datetime
Dim mymonth as integer
Mydate = now. adddays (-5)
Mymonth = month (mydate)
Return mymonth
End Function

Returns a formatted string.
Function date17 ()
Dim mydate as string
Mydate = format (now (), "YYYY ")
Return mydate
End Function
</SCRIPT>

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.