Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I create an Ordinal (legal) date format in VBA

Office / VBA General

How Do I create an Ordinal (legal) date format in VBA

by  Chance1234  Posted    (Edited  )
Here is a custom function adapted from the MS article
http://support.microsoft.com/kb/160988

Code:
Public Function pfun_OrdinalDate(dte_toformat As Date) As String

      Select Case Day(dte_toformat)
         Case 1, 21, 31
            daysuffix$ = Day(dte_toformat) & "st "
         Case 2, 22
            daysuffix$ = Day(dte_toformat) & "nd "
         Case 3, 23
            daysuffix$ = Day(dte_toformat) & "rd "
         Case Else
            daysuffix$ = Day(dte_toformat) & "th "
      End Select
      
      pfun_OrdinalDate = daysuffix$ & Format$(dte_toformat, "mmmm") & Format$(dte_toformat, " yyyy")

        
End Function

to test

Code:
?pfun_OrdinalDate(date())
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top