two newbie questions ... "date from string"
Daan Hoogland
hoogland at astron.nl
Tue May 13 08:47:21 EDT 2003
Thanks again,
I wrote my own, using string.split() and string.atoi(). It's not very generic
but it works for now.
It aroused some questions on inheritence and especially overloading. Can you
give me any pointers to reading on such issues?
also could one say
datetime.datetime(time.strptime("2003-05-13 12:15:18:000000", "%Y-%m-%d% H:%M:%S"))
to get a datetime object?
On Tue, 13 May 2003, you wrote:
> 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.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list