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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:59:36+00:00 2026-06-15T04:59:36+00:00

I have a table which is populated with data from an external source. The

  • 0

I have a table which is populated with data from an external source. The problem is I am getting two different format of dates for the same column, there are some records in '%Y-%m-%d %H:%i' format and other in '%Y-%d-%m %H:%i%s' format and they are all VARCHAR type.

I know how to convert a string type date field to a date/datetime field but how do I handle discrepancies in the way the dates are coming? Is it possible to Update dates on the basis of their individual format, so that I can apply a WHERE condition for updates to take place ONLY WHERE date_field is of '%Y-%m-%d %H:%i' format, and then another query to make updates for date field in '%Y-%d-%m %H:%i%s' format?

Right now when I try updating the tables with a common query I get error for the fields which donot match the format:

UPDATE my_table 
SET my_date_field = STR_TO_DATE(my_date_field,'%Y-%m-%d %H:%i:%s');

RESPONSE: Error Code: 1411. Incorrect datetime value: ’10-22-12 15:00′ for function str_to_date

UPDATE my_table 
SET my_date_field = STR_TO_DATE(my_date_field,'%Y-%d-%m %H:%i');

RESPONSE: Error Code: 1292. Truncated incorrect datetime value: ‘2010-01-01 00:00:00’

  • 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-15T04:59:37+00:00Added an answer on June 15, 2026 at 4:59 am

    for this value 10-22-12 15:00 you should use, %y-%d-%m %H:%i

    while for 2010-01-01 00:00:00, it should be %Y-%m-%d %H:%i:%s

    so your query will use CASE

    UPDATE my_table 
    SET my_date_field = (CASE WHEN CHAR_LENGTH(my_date_field) = 14 
                              THEN STR_TO_DATE(my_date_field,'%y-%d-%m %H:%i')
                              ELSE STR_TO_DATE(my_date_field,'%Y-%m-%d %H:%i:%s')
                          END)
    
    • See SQLFiddle Demo

    Other Source

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

Sidebar

Related Questions

I have a table view which is populated from data from an SQLite database.
I have a table which is being dynamically populated, each row contains two textfields
I have a table which is being dynamically populated from MySQL. The table has
I have a table which stores the data related to posts in this format
I have a data table which is populated with data unrelated to drupal content
I have a table which is populated by values obtained from mysql database. I
I have a JTable that get's populated with data from a MySQL Table, but
I have a table populated with data from the database, where each row has
I have a table which is already populated. I need to change the data
I have a csv file from which I have to populate different tables in

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.