Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleFind ordinal extensions (as in 1st, 2nd, 143rd, etc.)
Keywordsordinal extension, 1st, 2nd, 3rd
CategoriesAlgorithms, Strings
 
By Peter Chamberlin.
 
' Extend Date Number to Include Text Suffix
Public Function DateExtension(ByVal DateNum) As String
Dim DateRemainder As Integer

   ' Default to Most Common Extension
   DateExtension = "th"

   ' Handle ?11th through ?13th
   DateRemainder = DateNum Mod 100

   ' If Not An Exception
   If DateRemainder < 11 Or DateRemainder > 13 Then

      ' Get Right Digit
      Select Case DateNum Mod 10

         ' Update Appropriate Extension
         Case 1: DateExtension = "st"
         Case 2: DateExtension = "nd"
         Case 3: DateExtension = "rd"

      End Select

   End If

   ' Add Extension to Original Number
   DateExtension = DateNum & DateExtension

End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated