Nuts & Bolts for any eCommerce site
How it all comes together
Heres what you are looking for

“getS” Code Snippet

Facebook
Twitter
Reddit
LinkedIn

Formatting dates is something everybody likes to do, and everybody has their favorite way of formatting it. ASP has a few built in functions to enable us to output it in almost any format we like. However, something I’ve always wanted from Classic ASP was the ability to get the day suffix. Such as turning ‘January 1, 2012’ to ‘January 1st, 2012’. It’s easier to read and looks a lot nicer. Classic ASP has no support for this so here is a small snippet giving an example of how this can be accomplished and a few examples.

Example (pastebin):

<% currDate = NOW() Response.write("Today is the " & DAY(currDate) & getS(DAY(currDate)) & "<br />") ' Today is the 11th  '  currDate = DateAdd("d", 1, currDate)  Response.write("Tomorrow is the " & DAY(currDate) & getS(DAY(currDate)) & "<br />")  ' Tomorrow is the 12th %>

Source (pastebin):

<% '' ' A basic copy of PHP's version of date('S') ' "English ordinal suffix for the day of the month, 2 characters" ' @param int day The day suffix you are looking for. ' @return st ring This is the suffix you were looking for. '' Function getS(fn_day)  If fn_day = "" Then fn_day = CStr(DAY(NOW()))  Else fn_day = CStr(CInt(fn_day)) End If  fnll = Mid(fn_day, len(fn_day), 1) If len(fn_day) = 1 Then fndl = -1  Else fndl = Mid(fn_day, len(fn_day)-1, 2)  End If  If fndl >= 11 AND fndl <= 13 Then  getS = "th"  Exit Function  ElseIf fnll = 1 Then  getS = "st"  Exit Function  ElseIf fnll = 2 Then  getS = "nd"  Exit Function  ElseIf fnll = 3 Then  getS = "rd"  Exit Function  Else  getS = "th"  Exit Function  End If End Function %>

(Source: Skynet Solutions)

By Blaine Schmeisser

More Articles

Need eCommerce web support?

Give us a shout today! We won't bite.....hard.