datetime.stdptime help

Laszlo Nagy gandalf at shopzeus.com
Tue May 27 11:34:24 EDT 2008


            def str2datetime(s):
                #28 May 2008 12:38:16 BDT
                return time.strptime(s,"%d %b %Y %H:%M:%S %Z")

            #.... some code here....
            print repr(pd)
            print str2datetime(pd)


Result:

'24 May 2008 12:38:16 BDT'
Traceback (most recent call last):
  File "__init__.py", line 40, in <module>
    print ssc.get_order_data('202-9810306-3236320')
  File 
"/usr/local/www/vhosts/zeusd1/fantasy/controller/sites/ControllerBase.py", 
line 306, in get_order_data
    print str2datetime(pd)
  File 
"/usr/local/www/vhosts/zeusd1/fantasy/controller/sites/ControllerBase.py", 
line 299, in str2datetime
    return time.strptime(s,"%d %b %Y %H:%M:%S %Z")
  File "/usr/local/lib/python2.5/_strptime.py", line 331, in strptime
    (data_string, format))
ValueError: time data did not match format:  data=24 May 2008 12:38:16 
BDT  fmt=%d %b %Y %H:%M:%S %Z

I think that the format is correct. What am I doing wrong?

Thanks,

   Laszlo




More information about the Python-list mailing list