SearchSearch   MemberlistMembers   RegisterRegister   ProfileProfile   Log inLog in 

How To Show Dates in 'Long Format' in ASP

 
Post new topic   Reply to topic    Open Hosting Internet Solutions Forum Index -> Articles and Tutorials -> Server Side Web Development
View previous topic :: View next topic  
Author Message
Nick
Forum Moderator


Joined: 18 Jun 2002
Posts: 3635

PostPosted: Wed Mar 08, 2006 2:41 pm    Post subject: How To Show Dates in 'Long Format' in ASP Reply with quote

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())
%>
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Open Hosting Internet Solutions Forum Index -> Articles and Tutorials -> Server Side Web Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.11 © 2001, 2002 phpBB Group
FAQClick here for help using the phpBB forum