Return to Snippet

Revision: 10840
at January 15, 2009 14:16 by chombee


Updated Code
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")

Revision: 10839
at January 15, 2009 14:16 by chombee


Updated Code
def format_date_numerical(date):
    """Take a date or datetime or time 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")

Revision: 10838
at January 15, 2009 14:15 by chombee


Initial Code
def format_date_numerical(date):
    """Take a 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 datetime object and return a string of the form Thirsday 15 January 
    2009."""
    return date.strftime("%A %d %B %Y")

Initial URL


Initial Description
[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.)

Initial Title
Formatting date strings in Python

Initial Tags


Initial Language
Python