Solved

Amending php myadmin sql database

Posted on 2014-11-10
6
243 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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