Solved

Amending php myadmin sql database

Posted on 2014-11-10
6
237 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 10

Expert Comment

by:JEaston
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 10

Expert Comment

by:JEaston
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 10

Accepted Solution

by:
JEaston earned 500 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now