[wd_asp elements=’search’ ratio=’100%’ id=1]

Update Date format in DB from Varchar to Date

17th July 2013

MySql

mysql codehaven category

Run the following in phpmyadmin sql area.

UPDATE datatest set newdate=datetochange

‘datatest’ is the tablename

newdate = date format (2013-06-23)
datetochange = varchar (23/06/2013)

This should update all the old ways of storing the date to the new format, if you have stored it wrongly!
(when testing this my data became (2030/07/22)!!!

But the better way of doing is this: –

UPDATE cmdata
SET newdate = str_to_date( date, '%d/%m/%Y' );

Which worked
newdate was the new field with date format
date was the old varchar field