Quote:
|
Originally Posted by Steveire
Thanks both, but it's not in the form I'd like, ie '31 January 2006', '1 Febraury 2006'. Is that as simple? I checked some of the documentation on ptyhon.org, but didn't immediately find anything.
|
Just as the time module has the strftime function, which converts a timestamp into a string based on a user-specified formatting template, so too do the objects in the datetime module:
import datetime
today = datetime.date.today()
yesterday = today - datetime.timedelta(days = 1)
print today.strftime("%e %B %Y"), yesterday.strftime("%e %B %Y") The formatting codes seem to tally with those used in the standard Unix "date" command (IIRC, PHP and SQL use the same codes as well). The
time module doc page has a list of formatting codes, but this does not appear to be complete. At least under Linux, I find that "%e" represents the day of the month (as it does with the Unix date command), yet this is not listed in the Python documentation.