.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> DateTime >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Much Better Long Date Time Function

Posted By:Hefin Dsouza       Posted Date: August 12, 2009    Points: 10    Category: DateTime    URL: http://www.dotnetspark.com  
 

This is MuchBetterLongDateTime Function which returns a String value of the given datetime object.
It also automatically adds a post fix of st to date.

Public Shared Function MuchBetterLongDateFormat(ByVal [date] As DateTime) As String

Dim day As Integer = [date].Day
Dim post As String
Select Case day
Case 1, 21, 31
post = " st ,"
Case 2, 22
post = " nd ,"
Case 3, 23
post = " rd "
Case Else
post = " th ,"
End Select
Dim month As String = ""

Select Case [date].Month
Case 1
month = " January "
Case 2
month = " February "
Case 3
month = " March "
Case 4
month = " April "
Case 5
month = " May "
Case 6
month = " June "
Case 7
month = " July "
Case 8
month = " August "
Case 9
month = " September "
Case 10
month = " October "
Case 11
month = " November "
Case 12
month = " December "
End Select


Return [date].Day & post & [date].DayOfWeek.ToString() & " ," & month & [date].Year

End Function
Usage is Simple

TextBox1.Text = ExtendDate.MuchBetterLongDateFormat(DateTime.Now)

OutPut

13 th ,Thursday , August 2009

================================================================================
Regards Hefin Dsouza


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend