[Zope] RE: Quick question on timedate format

Martin Diers martin at diers.us
Wed Nov 12 12:20:15 EST 2003


Hello Ben,

I'm probably wrong, but I don't think there is any existing module that has this precise function.

You can create a Python function that does works something like this:


def ordinalize(number)
    numstring="%d" % number
    if number >= 11 and number <= 19:
        output = number + "th"
    elif numstring[-1] = "1":
        output = "%d%s" % number, "st"
    elif numstring[-1] = "2":
        output = "%d%s" % number, "nd"
    elif numstring[-1] = "3":
        output = "%d%s" % number, "rd"
    else:
        output = "%d%s" % number, "th"
    ordinalize = output

I did not test this, and I'm sure I screwed up my syntax somewhere since I am going from memory,
but hopefully, you get the idea


> Sorry to trouble you. I have spent hours looking on the web for the information.
> Basically I want to get the 'st,nd,th etc' part of the day of the month in my dates.
> I have:
>
> <dtml-var EndingDate fmt="day">
>
> Which obviously comes out as 11 for today. How do I make it come out as 11th?
>
> Much appreciated,
>
> Ben




More information about the Zope mailing list