INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA Visual Basic for Applications (Microsoft) FAQ

Office / VBA General

How Do I create an Ordinal (legal) date format in VBA by Chance1234
Posted: 2 Oct 07

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())

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close