Formatted Date Time in ASP Dot Net . Ex : Monday 25th Jan 2010 17:35:34

Chikul
Posted by Chikul under ASP.NET category on | Views : 2944
OutPut : Monday 25th Jan 2010 17:35:34


Partial Class Default6
Inherits System.Web.UI.Page

Function fnDateTime() As String

Dim strDate As String = ""

Dim intDay As Integer = Date.Now.Day
Dim DateSuffix As String = ""

Select Case intDay
Case 1, 21, 31
DateSuffix = "st"
Case 2, 22
DateSuffix = "nd"
Case 3, 23
DateSuffix = "rd"
Case Else
DateSuffix = "th"
End Select

Dim intMonth As Integer = Date.Now.Month
Dim MonthofYear As String = ""

Select Case intMonth
Case 1
MonthofYear = "Jan"
Case 2
MonthofYear = "Feb"
Case 3
MonthofYear = "Mar"
Case 4
MonthofYear = "Apr"
Case 5
MonthofYear = "May"
Case 6
MonthofYear = "Jun"
Case 7
MonthofYear = "Jul"
Case 8
MonthofYear = "Aug"
Case 9
MonthofYear = "Sep"
Case 10
MonthofYear = "Oct"
Case 11
MonthofYear = "Nov"
Case 12
MonthofYear = "Dec"
End Select

Dim intDayOfWeek As Integer = Date.Now.DayOfWeek
Dim DayofWeek As String = ""

Select Case intDayOfWeek
Case 1
DayofWeek = "Monday"
Case 2
DayofWeek = "Tuesday"
Case 3
DayofWeek = "Wednesday"
Case 4
DayofWeek = "Thursday"
Case 5
DayofWeek = "Friday"
Case 6
DayofWeek = "Saturday"
Case 7
DayofWeek = "Sunday"
End Select

strDate &= DayofWeek & " " 'Monday, Tuesday, Wednesday etc
strDate &= DateTime.Now.Day.ToString() '1, 2, 3, 4 etc
strDate &= DateSuffix & " " 'st, nd, rd, th
strDate &= MonthofYear & " " 'Jan, Feb etc
strDate &= DateTime.Now.Year.ToString() & " " '2010, 2011 etc
strDate &= DateTime.Now.Hour.ToString & ":" 'hours
strDate &= DateTime.Now.Minute.ToString() & ":" 'minute
strDate &= DateTime.Now.Second.ToString() 'seconds

Return strDate
End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblDateTime.Text = fnDateTime()
End Sub

End Class

Comments or Responses

Login to post response