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

Source: Internet
Author: User

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 ))
Wocould 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.