Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Displaying the server's current date

0.00/5 (No votes)
14 Feb 2000 1  
A simple routine to display the current date of the server in the clients browser

Here's a simple function to display the date on the server, either in the form '7 Feb 2002' or 'Thursday 7th February, 2002' depending on whether Abbreviate is True or False.

' DateVal is the date to display

' If Abbreviate is True then the date is displayed in short form

' Otherwise it's displayed verbose

Function DateString(DateVal, Abbreviate)
Dim intDate, strDay, strMonth, strYear

    intDate  = Day(DateVal)
    strYear  = Year(DateVal)
    
    if Abbreviate Then
        strMonth = MonthName(Month(DateVal), True)
        DateString = intDate & " " & MonthName(Month(DateVal), True) & " " & strYear
    Else
        strMonth = MonthName(Month(DateVal))
        strDay   = WeekDayName(WeekDay(DateVal), False, vbSunday)

        Dim suffix
        suffix   = "th"
        Select Case intDate
            case 1,21,31 : suffix = "st"
            case 2,22    : suffix = "nd"
            case 3,23    : suffix = "rd"
        End Select

        DateString  = strDay & " " & intDate & suffix & " " & strMonth & ", " & strYear
    End If
End Function

To use this in an ASP page just include the above script, then add the following where you wish to display the date:

<p>Today is <%= DateString(Date(), False) %></p>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here