Some common functions (VB) for processing datetime in ASP. NET)

Source: Internet
Author: User
Some common functions (VB) for processing datetime in ASP. NET)

Post: Andy. m Date: popularity: 69

'Uses the timespan method to subtract a certain number of days
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

'Uses the adddays method to subtract X number of days
Public Function date2 ()
Dim newtime as datetime
Newtime = datetime. Now. adddays (-7)
Dim s as string = newtime
Return s
End Function

'Thanks to Paul czywcstmski for this idea
'This probably (in my opinion) offers the most flexibility found so far
'Change where the mm/DD/yyyy to whatever
'Response. Write (system. String. Format ("{0: d}", newtime ))
'Could return just the name of the day
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

'Uses the tolongtimestring Method
Public Function date5 ()
Dim newtime as datetime
Newtime = now ()
Return newtime. tolongtimestring ()
End Function

'Uses the toshorttimestring Method
Public Function date6 ()
Dim newtime as datetime
Newtime = now ()
Return newtime. tow.timestring ()
End Function

'Uses the tolongdatestring Method
Public Function date7 ()
Dim newtime as datetime
Newtime = now ()
Return newtime. tolongdatestring ()
End Function

'Uses the toshortdatestring Method
Public Function date8 ()
Dim newtime as datetime
Newtime = now ()
Return newtime. tow.datestring ()
End Function

'Uses formatdatetime function General Format
Function date9 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 0)
End Function

'Uses formatdatetime function longdate format
Function date10 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 1)
End Function

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

'Uses formatdatetime function longtime format
Function date12 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 3)
End Function

'Uses formatdatetime function processing time format
Function date13 ()
Dim newtime as datetime
Newtime = datetime. Now. Subtract (New timespan (7, 0, 0, 0 ))
Return formatdatetime (newtime, 4)
End Function

'Bring back just the name of the day
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 integer of what day of week
Function date15 ()
Dim mydate as datetime
Dim myweekday as integer
Mydate = now. adddays (-5)
Myweekday = weekday (mydate)
Return myweekday
End Function

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

'Returns just a formatted string
'This method provides just formatting
'Very flexible with not a lot of code
Function date17 ()
Dim mydate as string
Mydate = format (now (), "YYYY ")
Return mydate
End Function
</SCRIPT>

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.