strptime dilemma with Python 2.5

P

pythonista

Hello,
I have a date string looking like the following:

"Sun May 30 07:25:17 2010"

With Python 2.6, the %f is supported (it parses the microseconds), so
that this statement works:

dt = datetime.strptime(s, "%a %b %d %H:%M:%f %Y")

However, with Python 2.5, (which is supported on the live Webfaction
server I'm using), %f is not supported.

Is there a straightforward way to simply ignore the :17 microseconds
in the original string?

Maybe force it to "00" ? - but without having to actually change the
original string by removing the ":17" ?

If I simply leave out the ":%f" in the strptime call, I get back a "
ValueError: time data did not match format: data=Sun May 30
19:33:54 2010 fmt=%a %b %d %H:%M %Y


Hoping for a simple solution that someone is familiar with
Thanks
Steve
 
M

MRAB

pythonista said:
Hello,
I have a date string looking like the following:

"Sun May 30 07:25:17 2010"

With Python 2.6, the %f is supported (it parses the microseconds), so
that this statement works:

dt = datetime.strptime(s, "%a %b %d %H:%M:%f %Y")

However, with Python 2.5, (which is supported on the live Webfaction
server I'm using), %f is not supported.

Is there a straightforward way to simply ignore the :17 microseconds
in the original string?

Maybe force it to "00" ? - but without having to actually change the
original string by removing the ":17" ?

If I simply leave out the ":%f" in the strptime call, I get back a "
ValueError: time data did not match format: data=Sun May 30
19:33:54 2010 fmt=%a %b %d %H:%M %Y


Hoping for a simple solution that someone is familiar with

The date string looks like it has hours, minutes and seconds, not hours,
minutes and microseconds.
 
P

pythonista

You know why it looks like it has seconds and not microseconds?

Because it does, and I'm on something.

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top