2

Hi I'm gathering some info from other website with the time in all formats. MySQL datatype is 'DATATIME', I'm getting the following error.

OperationalError: (1292, "Incorrect datetime value: 'Tue, 27 Jan 2015 05:59:09 GMT' for column 'date' at row 1")

Any help on this is appreciated.

2 Answers 2

3

To Handle your particular error, do as follows

import datetime
your_date = "Tue, 27 Jan 2015 05:59:09"
print datetime.datetime.strptime(your_date, '%a, %d %b %Y %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S')

Incase there is a finite set of websites, you need to handle the date formats individually. Please go through below link.

http://strftime.org/

Sign up to request clarification or add additional context in comments.

3 Comments

how GMT and +0530 is represented in the datetime.strptime() fileds after %a, %d %b %Y %H:%M:%S.. my date format is Tue, 27 Jan 2015 05:59:09 GMT and Wed, 12 Sep 2012 10:50:34 +0530
Its showing a ValueError: unconverted data remains: GMT
I got the solution for GMT, how can i represent Wed, 12 Sep 2012 10:50:34 +0530 –
2

I think The Datetime format your passing is different from MySql's .. The Mysql Dateformat is like YYYY-MM-DD HH:MM:SS

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.