Click here to Skip to main content
14,105,616 members
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 14 Feb 2000
Licenced CPOL

Displaying the server's current date

, 14 Feb 2000
Rate this:
Please Sign up or sign in to vote.
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
        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>


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.

You may also be interested in...


Comments and Discussions

GeneralGreat snippet Pin
Stober3-Jun-00 10:57
memberStober3-Jun-00 10:57 
GeneralSimple and handy Pin
Pete2-May-00 17:52
memberPete2-May-00 17:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190518.1 | Last Updated 15 Feb 2000
Article Copyright 2000 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid