two newbie questions ... "date from string"
Andrew Bennetts
andrew-pythonlist at puzzling.org
Tue May 13 08:15:56 EDT 2003
On Tue, May 13, 2003 at 11:30:30AM +0000, Duncan Booth wrote:
> Daan Hoogland <hoogland at astron.nl> wrote in
> news:mailman.1052821639.7509.python-list at python.org:
>
> >
> > Any idea on the datetime_from_string parsing question, anyone? Or do I
> > have to write one myself?
> >
> > I can't find a function to convert a date string back to a datetime
> > object. The date i have is returned by postgresql in the (well known)
> > format "YYYY-MM-DD hh:mm:ss:mmmmmm". Am i missing something in the
> > help? Or is there an extended Date package that does this?
>
> >>> time.strptime("2003-05-13 12:15:18:000000", "%Y-%m-%d %H:%M:%S")
> (2003, 5, 13, 12, 15, 18, 1, 133, -1)
>
> Unfortunately, unless you are using Python 2.3, you will find that not all
> platforms include the time.strptime function (I think Unix has it, Windows
> doesn't). In Python 2.3 strptime is implemented in a module _strptime.py
> which should be useable on 2.2.1+ if you copy it.
Python 2.3's _strptime module uses the new datetime module, which is a C
extension, so using it in 2.2 is non-trivial.
-Andrew.
More information about the Python-list
mailing list