Nick Forum Moderator

Joined: 18 Jun 2002 Posts: 3635
|
Posted: Wed Mar 08, 2006 2:41 pm Post subject: How To Show Dates in 'Long Format' in ASP |
|
|
How To Show Dates in Long Format in ASP
A function to display dates in their long format, including day abbreviations e.g. "th" and "nd".
Sometimes the FormatDateTime function in VB/ASP just isn't good enough. Especially when you want a customised date format. There are numerous ways of chopping up dates, and so I've put together a simple, small function for one such format. It ensures the dates are returned with DD** - Month name - YYYY. An example being 18th February 2003. Not all date formats return the "th".
| Code: | <%
Function doDate(prmDate)
Dim strDay, strDayAbbrev, strMonth, strYear
'Select the Day from the parameter
strDay = Day(prmDate)
'Set default abbreviation to th, as this is the most common
strDayAbbrev = "th"
'Change abbreviation if the value of the Day requires
If strDay = "1" Or strDay = "21" Or strDay = "31" Then strDayAbbrev = "st" End If
If strDay = "2" Or strDay = "22" Then strDayAbbrev = "nd" End If
If strDay = "3" Or strDay = "23" Then strDayAbbrev = "rd" End If
'Find the name of the month
strMonth = Monthname(Month(prmDate))
'Find the year
strYear = Year(prmDate)
'Put all of the component together
doDate = strDay & strDayAbbrev & " " & strMonth & " " & strYear
End Function
%> |
To use this on an ASP page, copy and paste the above function, and where you want to display a date, use the following.
| Code: | <%
Response.Write doDate(Date())
%> |
|
|