Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8519955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:23:50+00:00 2026-06-11T06:23:50+00:00

I am passing ‘2012-09-10 00:00:00-05:00’ to a MySQL query. This value is retrieved using

  • 0

I am passing '2012-09-10 00:00:00-05:00' to a MySQL query. This value is retrieved using the pytz module for Python.

import pytz
class MyClass():
    def __init____(self):
        self.tz = pytz.timezone(settings.TIME_ZONE)
        todaystart = self.tz.localize(datetime.now(self.tz).replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=None), is_dst=None).astimezone(self.tz)

The MySQL query is this, after todaystart has been substituted in:

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

If I execute this query directly, it returns data as expected. If I put this query into code it gives this error: Warning: Truncated incorrect datetime value: '2012-09-09 00:00:00-05:00'

The code I am using is this (within Django):

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

I didn’t see an offset format string in the MySQL docs for str_to_date. I would prefer to keep that offset, as the data is returned for a 3rd party system and by keeping it in place I don’t have to do any logic between that return and executing the query with the returned date. However, I don’t think it has to do with the offset since it works if I run it directly.

What have I done incorrectly that would cause this Warning to appear when Python runs the query against MySQL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:23:51+00:00Added an answer on June 11, 2026 at 6:23 am

    Marc B had it right.

    When executed directly, you are getting the warnings, but probably not noticing:

    mysql> SELECT * FROM mytable WHERE created > UNIX_TIMESTAMP(STR_TO_DATE('2012-09-10 00:00:00-05:00','%Y-%m-%d %k:%i:%s') - INTERVAL 1 DAY);
    Empty set, 3 warnings (0.00 sec)
    
    mysql> show warnings;
    +---------+------+----------------------------------------------------------------------+
    | Level   | Code | Message                                                              |
    +---------+------+----------------------------------------------------------------------+
    | Warning | 1292 | Truncated incorrect datetime value: '2012-09-10 00:00:00-05:00'      |
    | Warning | 1292 | Truncated incorrect datetime value: '2012-09-10 00:00:00-05:00'      |
    | Warning | 1292 | Incorrect datetime value: '1347148800' for column 'created' at row 1 |
    +---------+------+----------------------------------------------------------------------+
    3 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm passing a map of strings from native c++ class to c# using c++/CLI.
I am passing vlues to javasript function from PHP in following manner: <select onChange=display_databody(<?=$manufacturers_id?>,<?=$modelID?>,this.value,<?=**$month_year**?>);>
When passing boolean value from controller to the view using ViewData, how do I
Passing a Enum value as a parameter from JSF This question already deals with
Am passing a value using href tag In first page Href tag used as
passing post data using cURL requires that the name of the input. However, I
Passing in an Expression to a Linq query behaves differently depending on syntax used,
I am having issues passing a dynamic parameter to a JavaScript function using innerHTML.
I'm passing to perl from php using escapeshellarg system(perl -e ' . escapeshellarg($inp) .
When passing forward declared struct or a class, one has to pass it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.