.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

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

Posted By:Prasanti Prusty       Posted Date: January 25, 2010    Points: 10    Category: DateTime    URL: http://www.dotnetspark.com  

Formatted Date Time in ASP.Net . Ex : 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


     

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