[Tutor] stripping 0's from 01's - 09's
Norman Khine
norman at khine.net
Thu Jun 4 21:04:43 CEST 2009
Hello,
Simple, I guess, but I am trying to do a formated date function, which
I have working but for a small annoyance in that:
>>> from datetime import date
>>> def format_date(day):
... if day > 3 and day < 14:
... return '%b %dth %Y'
... indicator = day % 10
... if indicator == 1:
... return '%b %dst %Y'
... elif indicator == 2:
... return '%b %dnd %Y'
... elif indicator == 3:
... return '%b %drd %Y'
... else:
... return '%b %dth %Y'
...
>>> today = '2009-06-04'
>>> year, month, day = today.split('-')
>>> date_object = date(int(year), int(month), int(day))
>>> format = format_date(date_object.day)
>>> formated_date = date_object.strftime(format)
>>> formated_date
'Jun 04th 2009'
It will be much better to have:
'Jun 4th 2009'
How would you go about in doing this?
Thanks
More information about the Tutor
mailing list