Solved

Amending php myadmin sql database

Posted on 2014-11-10
6
246 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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…

679 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