Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Amending php myadmin sql database

Posted on 2014-11-10
6
Medium Priority
?
280 Views
Last Modified: 2014-11-10
Hello,

I need some help/advice on updating my database.

Stupidly i set my Date column structure to varchar(250) then populated the database with 226048 rows of code  :(

is there away i can convert the current date (displayed like 18/10/2014) and then convert the column to be Date ??
0
Comment
Question by:runnerjp2005
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:John Easton
ID: 40432706
You should be able to create a new date column, and then update it with the date in the varchar column.  After checking the data you can then drop the varchar column.
0
 

Author Comment

by:runnerjp2005
ID: 40432712
Thats a good idea!!!

what sql statement would i need to update from `date` to date2?
0
 
LVL 11

Expert Comment

by:John Easton
ID: 40432722
I've only done this in MS SQL, but MySQL should be able to do the same.  From memory (assuming you are editing every row in the table) all you should need to do is (replacing the field and table name accordingly):

UPDATE myTable SET newDate = oldDate

Open in new window


Needless to say, if this is a live system please backup first.  Any SQL that can update large volumes of data could cause data loss if it fails, has a typo etc.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:runnerjp2005
ID: 40432729
Yer currently doing this on a copy of the table

UPDATE `horses2` SET `Date2` = `Date`

tried the above and it updates 0 rows :S
0
 
LVL 11

Accepted Solution

by:
John Easton earned 2000 total points
ID: 40432743
Just created a table to test this, and got the same result.  You need to add the Str_to_date function as shown below:
UPDATE `datetest` SET `newdate`=STR_TO_DATE(`olddate`,'%d/%m/%Y')

Open in new window

This assumes all the dates are entered in UK format (i.e. 20/01/2014).  If the format is different you should edit the format.  Guidance is available here:  Date Format
0
 

Author Closing Comment

by:runnerjp2005
ID: 40432744
Ta Bud saved me ALOT of time there :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question