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 8502023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:22:18+00:00 2026-06-11T01:22:18+00:00

I have the following query that running in SQLyog SELECT * FROM mytable WHERE

  • 0

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?

  • 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-11T01:22:20+00:00Added an answer on June 11, 2026 at 1:22 am

    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?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
I have the following query: SELECT * FROM versions WHERE path LIKE '%/dir1%' that
I have the following query that retrieve the number of users per country; SELECT
I have the following query: SELECT wm_concat(DISTINCT NAME) as Methods FROM TPM_TRAININGPLAN JOIN TPM_DELIVERYMETHODS
I have the following query: select * from winners join profiles on winners.subscriber_id =
I have the following query: SELECT COLUMN1, COLUMN2, COUNT(*) FROM TABLE WHERE COLUMN3 IS
I have the following query that I am running on my database server but
I have the following SQL query: SELECT DISTINCT business_key FROM Memory WHERE concept <>
Let's assume I have the following query: SELECT address FROM addresses a, names n
I am running the following query SELECT * FROM wp_posts WHERE (post_title LIKE 'Professionally')

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.