Codefixer - ASP tutorials, resources and software
New MS SQL 2008 Available – DiscountASP.NET
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Sunday 7 September
MembersPro PayPal - ASP Membership software

USA & Europe Data Centers – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Dates with the Ordinal Suffix

Download the code

Notice this example has an ordinal suffix: Sunday 7th September
Below is the code that will do this.

<%
'Declare variables
Dim curDayOftheWeek, curMonth, curDay
'Return the numeric day of the week Sunday = 1 etc
curDayOftheWeek=(weekday(date))
Select Case curDayOftheWeek
Case 1 Response.write("Sunday")
Case 2 Response.write("Monday")
Case 3 Response.write("Tuesday")
Case 4 Response.write("Wednesday")
Case 5 Response.write("Thursday")
Case 6 Response.write("Friday")
Case 7 Response.write("Saturday")
End select
'Write out the numeric day of the month
Response.Write(" "&day(date))
'Return the numeric day of the month and assign to variable curDay
curDay=day(date)
'Write out the ordinal suffix according to the numeric day of the day
Select Case curDay
Case 1,21,31 response.write("st")
Case 2,22 response.write("nd")
Case 3,23 response.write("rd")
Case else response.write("th")
End select
'add a space
response.write " "
'Return the numeric month of the year and assign to variable curMonth
'1=January, 2=February etc
curMonth=(month(date))
Select Case curMonth
Case 1 Response.write("January")
Case 2 Response.write("February")
Case 3 Response.write("March")
Case 4 Response.write("April")
Case 5 Response.write("May")
Case 6 Response.write("June")
Case 7 Response.write("July")
Case 8 Response.write("August")
Case 9 Response.write("September")
Case 10 Response.write("October")
Case 11 Response.write("November")
Case 12 Response.write("December")
End Select
%>


Other date and time related tutorials:
Read more on the Date, Time and Now VBScript functions
Here's a code snippet to display the day and date (eg. Mon 25 December).
How to get the current month name
Display the dates and times
Time and Date based greetings
IsDate Function
The DateDiff DateAdd and DatePart Functions





If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.

ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software