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.
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>
Chris Maunder
Founder
The Code Project
Canada
Member
Follow on Twitter
Google
|
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.
|