Truncated incorrect datetime value

I have the following query that running in SQLyog

SELECT * FROM mytable WHERE created > UNIX_TIMESTAMP(STR_TO_DATE('2012-09-09 00:00:00-05:00','%Y-%m-%d %k:%i:%s') - INTERVAL 1 DAY);

If I run the same query in Python or Django, I get this message:

Warning: Truncated incorrect datetime value: '2012-09-09 00:00:00-05:00'

I've printed out the query from python to ensure it's the same as above. It is identical (including the ending semicolon). I suspect that it's having issues with the timezone offset, but I don't know why it'd work in SQLyog then.

The query that is printed is:

--------------------------------------------------
SELECT * FROM sb_bans WHERE created > UNIX_TIMESTAMP(STR_TO_DATE('2012-09-09 00:00:00-05:00','%Y-%m-%d %H:%i:%s') - INTERVAL 1 DAY);
--------------------------------------------------

The Django code used to run this query is:

query = """SELECT * FROM sb_bans WHERE created > UNIX_TIMESTAMP(STR_TO_DATE('2012-09-09 00:00:00-05:00','%Y-%m-%d %H:%i:%s') - INTERVAL 1 DAY);"""
myCursor = connections[system_db].cursor()
results = myCursor.execute(query)    # Dies on this statement
resultcount = results.fetchall()

Why does this query work when I run it directly, but it fails when executed by my code?

Answers


There is a difference between your two queries:

First:

STR_TO_DATE('2012-09-09 00:00:00-05:00','%Y-%m-%d %k:%i:%s')

Django code:

STR_TO_DATE('2012-09-09 00:00:00-05:00','%Y-%m-%d %H:%i:%s')

One has a %k, the other a %H. Perhaps that's the root of your problem?


Need Your Help

Jquery Validate Error on IE8-10

javascript jquery internet-explorer internet-explorer-8 jquery-validate

I have a checkout page in my e-commerce with jquery validate, in firefox/chrome it works correctly but in internet explorer 8 to 10, I receive the following error:

In C++, what is a virtual base class?

c++ virtual-inheritance

I want to know what a "virtual base class" is and what it means.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.