1st, 2nd, 3rd etc....

AnnaFoot

Registered User.
Local time
Today, 05:26
Joined
Dec 5, 2000
Messages
51
Hello,

Is there a way to display a date in a report using the th, st, nd, rd extensions at all?

i.e. december 1st 2005, rather than december 1 2005?

i could do it in code, but that would be a little annoying if there was a trick to it!

Anna
 
Hi -

The logic for adding a suffix to a number is not too difficult. Function NumSuffix() --see below-- should do it for any integer.

Function DateSay() --see below-- takes a date and, using Function NumSuffix(), returns a string in the format you specified.

Copy/paste the code to a new module.

Call the process with DateSay(#your date#), e.g.
Today is 13-Dec-05.
? datesay(date())
-or
? datesay(#12/13/05#)

They both return:
December 13th 2005

HTH - Bob
Code:
Public Function NumSuffix(MyNum As Variant) As String
'*******************************************
'Purpose:   Add suffix to a number
'coded by:  raskew
'Inputs:    ? NumSuffix(234)
'Output:    234th
'*******************************************

Dim n      As Integer
Dim x      As Integer
Dim strSuf As String

    n = Right(MyNum, 2)
    x = n Mod 10
    strSuf = Switch(n <> 11 And x = 1, "st", n <> 12 And x = 2, "nd", _
                    n <> 13 And x = 3, "rd", True, "th")
    NumSuffix = LTrim(str(MyNum)) & strSuf

End Function

Public Function DateSay(ByRef pDte As Date) As String
Dim strHold As String

    strHold = Format(pDte, "mmmm") & " " & NumSuffix(day(pDte)) & " " & Format(pDte, "yyyy")
    DateSay = strHold
    
End Function
 

Users who are viewing this thread

Back
Top Bottom