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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:16:14+00:00 2026-06-05T12:16:14+00:00

Hey I have an SQL Table which has a column for storing date but

  • 0

Hey I have an SQL Table which has a column for storing date but the date column has a type varchar. I want to change the type to date but I don’t want the actual data to be lost in that column. How can I achieve that.

Manually taking a backup of the table and then entering each entry? or there is some other cool way to do it ? Actually the data is huge

Thanks

  • 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-05T12:16:15+00:00Added an answer on June 5, 2026 at 12:16 pm

    My way of doing this:

    (1) Add a new column:

    ALTER TABLE yourtable 
    ADD COLUMN `new_date` DATE NULL AFTER `views`; 
    

    (2) Update the new column

    UPDATE yourtable SET new_date = old_date;
    

    Take care of the datas formatting in old_date. If it isn’t formatted yyyy-mm-dd, you might have to STR_TO_DATE or some string-replacements in this UPDATE-statement here to fit your purposes.

    Example:

    If your data looks like this: mmmm dd, yyyy, hh:mm (p.e. May 17, 2012, 8:36 pm) , you can update like this:

    UPDATE yourtable
    SET new_date = STR_TO_DATE(old_date, "%M %e, %Y");
    

    STR_TO_DATE basically reverse engineers string data to a date value.

    (3) Delete the old column

    ALTER TABLE yourtable 
    DROP COLUMN `old_date`; 
    

    (4) Rename the new column

    ALTER TABLE yourtable 
    CHANGE `new_date` `old_date` DATE NULL; 
    

    Done!

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

Sidebar

Related Questions

Hey guys, I have a column in an sql server table that is nvarchar(max).
Hey, I have a table called products that has a relationship with itself. This
Hey I have a name column in my table, suppose i get have name
hey guys, i want to convert datetime from string, i have string which contains
hey guys, i have 3 tables in my sql server database. 1. crossarticle_article has
Hey I have this code but it doesn't work because it is expecting a
I have another SQL/access 2007 question that seems really basic but I'm not sure
Hey guys, I have an application that I want to display some data from
Hey Guys, having an issue with Linq-to-SQL, I am basically doing the following but
I have a SQL Server cursor. I want to skip one iteration of the

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.