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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:55:58+00:00 2026-06-10T12:55:58+00:00

These queries require the string to date conversion because Timestamp is stored as a

  • 0

These queries require the string to date conversion because Timestamp is stored as a string, and the logging application is unchangeable.

I have a select query that works perfectly ->

(SELECT main.user_id, main.Timestamp
FROM `user_table` main
WHERE STR_To_DATE( main.Timestamp , '%a %b %d %H:%i:%s CST %Y' ) <
  (SELECT  MAX(STR_To_DATE( sub.Timestamp , '%a %b %d %H:%i:%s CST %Y' )) 
   FROM `user_table` sub
   WHERE sub.user_id = main.user_id ))

This will select ALL BUT most recently added user id and timestamp from my table.

However, when I try to insert this into another table…like so ->

INSERT INTO user_table_temp (`user_id`, `Timestamp`)
(SELECT main.user_id, main.Timestamp
FROM `user_table` main
WHERE STR_To_DATE( main.Timestamp , '%a %b %d %H:%i:%s CST %Y' ) <
  (SELECT  MAX(STR_To_DATE( sub.Timestamp , '%a %b %d %H:%i:%s CST %Y' )) 
   FROM `user_table` sub
   WHERE sub.user_id = main.user_id ))

I get the following error ->

#1411 - Incorrect datetime value: 'Mon Mar 14 16:10:10 CDT 2011' for function str_to_date

The reason for this is because my Timestamps are stored in two formats. One will store as ‘CST’ during non-daylight-savings time, the other will store as ‘CDT’ during daylight-savings time. When the INSERT INTO SELECT gets to the first row that has the opposite of what I’m querying against, it will fail with the above message.

I have also tried to COALESCE them, which also works when just running the select ->

INSERT INTO user_table_temp  (`user_id `, `Timestamp`)
(SELECT main.user_id , main.Timestamp
FROM `user_table` main
WHERE COALESCE(STR_To_DATE( main.Timestamp , '%a %b %d %H:%i:%s CDT %Y' ), STR_To_DATE( main.Timestamp , '%a %b %d %H:%i:%s CST %Y' )) <
  (SELECT  MAX(COALESCE(STR_To_DATE( sub.Timestamp , '%a %b %d %H:%i:%s CDT %Y' ), STR_To_DATE( sub.Timestamp , '%a %b %d %H:%i:%s CST %Y' ))) 
   FROM `user_table` sub
   WHERE sub.user_id = main.user_id ))

Why would this fail on an INSERT, but the SELECT would work?

  • 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-10T12:55:59+00:00Added an answer on June 10, 2026 at 12:55 pm

    I think it fails on INSERT because you’re not using a supported format. The supported formats . . .

    As a string in either ‘YYYY-MM-DD HH:MM:SS’ or ‘YY-MM-DD HH:MM:SS’
    format. A “relaxed” syntax is permitted here, too: Any punctuation
    character may be used as the delimiter between date parts or time
    parts. For example, ‘2012-12-31 11:30:45’, ‘2012^12^31 11+30+45’,
    ‘2012/12/31 11*30*45’, and ‘2012@12@31 11^30^45’ are equivalent.

    As a string with no delimiters in either ‘YYYYMMDDHHMMSS’ or
    ‘YYMMDDHHMMSS’ format, provided that the string makes sense as a date.
    For example, ‘20070523091528’ and ‘070523091528’ are interpreted as
    ‘2007-05-23 09:15:28’, but ‘071122129015’ is illegal (it has a
    nonsensical minute part) and becomes ‘0000-00-00 00:00:00’.

    As a number in either YYYYMMDDHHMMSS or YYMMDDHHMMSS format, provided
    that the number makes sense as a date. For example, 19830905132800 and
    830905132800 are interpreted as ‘1983-09-05 13:28:00’.

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

Sidebar

Related Questions

Do these two queries differ from each other? Query 1: SELECT * FROM Table1,
I have these two queries to test my output SELECT DISTINCT( providerId ), SUM((
These two queries work: SELECT u.id, u.email, COUNT(*) as Current FROM users u, rounds
Given these two queries: Select t1.id, t2.companyName from table1 t1 INNER JOIN table2 t2
Got these 2 queries: select d1.field_id_41 program_code, d1.field_id_48 program_group_code, t1.title program_lookup, t2.title group_title, t1.url_title
I've got these two queries: SELECT SELECT NamesRecord.NameID, NamesRecord.FulfillmentAddressID NameFulfillmentAddressID, ContractRecord.FulfillmentAddressID, ContractRecord.BillingAddressId FROM Magnet.dbo.ContractRecord
Given: Two queries that require filtering: select top 2 t1.ID, t1.ReceivedDate from Table t1
These 4 queries produce the desired result, however I want to wrap these queries
Which of these queries is more efficient, and would a modern DBMS (like SQL
I've read multiple examples on how these queries should be written but I'm struggling

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.