convert time

Ben Finney ben+python at
Sun Sep 11 01:30:18 EDT 2011

Steven D'Aprano <steve+comp.lang.python at> writes:

> But seriously... 2011-12 is not a proper date

It's valid by ISO 8601. The standard allows any number of parts to be
dropped, from least to most significant, in order to have a value with
deliberately reduced precision.


> Otherwise see the time and datetime modules:

    >>> import datetime
    >>> text = "2011-12"
    >>> datetime.datetime.strptime(text, "%Y-%m")
    datetime.datetime(2011, 12, 1, 0, 0)

 \            “It's not what you pay a man, but what he costs you that |
  `\                                             counts.” —Will Rogers |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list