Add st/nd/rd/th to a Number or Date (1st, 2nd...)

Need to write a number like "20" as "20th"?

Function NumberEnd(NumberIn)
Dim EndTagNum
EndTagNum = Right(NumberIn, 1)

Select Case EndTagNum
Case 1 NumberEnd = NumberIn & "st"
Case 2 NumberEnd = NumberIn & "nd"
Case 3 NumberEnd = NumberIn & "rd"
Case Else NumberEnd = NumberIn & "th"
End Select

End Function

How about an example of the number of days since the beginning of the year? What sounds better? If you have "111 day" on your page or "111st day".

Function DaysUsed()
Dim DaysFrom ''Holds number of days since the beginning of the year
Dim EndTagNum ''Holds last digit of DaysFrom
DaysFrom = DateDiff("d", "1/1/2001", Now)
EndTagNum = Right(DaysFrom, 1)
Select Case EndTagNum
Case 1 DaysUsed = DaysFrom & "st"
Case 2 DaysUsed = DaysFrom & "nd"
Case 3 DaysUsed = DaysFrom & "rd"
Case Else DaysUsed = DaysFrom & "th"
End Select
End Function

Source: Chuck Dearbeck
Viewed 16395 times