/ Published in: Python
[date](http://docs.python.org/library/datetime.html#datetime.date), [datetime](http://docs.python.org/library/datetime.html#datetime.datetime) and [time](http://docs.python.org/library/datetime.html#datetime.time) objects in Python have a [strftime](http://docs.python.org/library/datetime.html#strftime-behavior) method for creating string representations in whatever format you want. (See the strftime link for the strftime syntax.)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def format_date_numerical(date): """Take a date or datetime object and return a string of the form YYYY_MM_DD.""" return date.strftime("%Y_%m_%d") def format_date_pretty(date): """Take a date or datetime object and return a string of the form Thursday 15 January 2009.""" return date.strftime("%A %d %B %Y")