planet260
planet260

Reputation: 1474

Python DateTime Format Error

I am new at Python. I was trying to play with time and date objects. I wrote a simple test program to parse a string into a specific time format. But its throwing a ValueError. Can you please help me out here?

Here is the code:

import time
testDate = "Tuesday, Febuary 23 2011 12:00:00 UTC"
today = time.strptime(testDate,"%A, %B %d %Y %H:%M:%S %Z")
print today

and the error:

Traceback (most recent call last):
  File "D:\Python\PythonTest\src\helloWorld.py", line 3, in <module>
    today = time.strptime(testDate,"%A, %B %d %Y %H:%M:%S %Z")
  File "C:\Python27\Lib\_strptime.py", line 467, in _strptime_time
    return _strptime(data_string, format)[0]
  File "C:\Python27\Lib\_strptime.py", line 325, in _strptime
   (data_string, format))
ValueError: time data 'Tuesday, Febuary 23 2011 12:00:00 UTC' does not match format '%A, %B %d %Y %H:%M:%S %Z'

Upvotes: 0

Views: 1206

Answers (2)

badc0re
badc0re

Reputation: 3523

You had February misspelled. Your code works.

import time
testDate = "Tuesday, February 23 2011 12:00:00 UTC"
today = time.strptime(testDate,"%A, %B %d %Y %H:%M:%S %Z")
print today

Upvotes: 3

user2555451
user2555451

Reputation:

Very simple: you spelled "February" wrong:

import time
testDate = "Tuesday, February 23 2011 12:00:00 UTC"
today = time.strptime(testDate,"%A, %B %d %Y %H:%M:%S %Z")
print today

Originally, you had "February" spelled as "Febuary". Works fine once that is fixed.

Upvotes: 1

Related Questions