Mysql Q about dates in a varchar field

Soldato
Joined
4 Jul 2004
Posts
2,647
Location
aberdeen
Hi,
I have a massive table with dates in a varchar field like
01-feb-2009 (they are all like that)

Is there any way to convert it to a date field without losing any data and so i can order it correctly by date?

thanks
 
what I would do: (using php too)

1. create another column - newdate, or whatever. give it the type datetime or date, whatever you need.
2. run a query getting all your dates and primary key fields out into an array
3. foreach through your results, reformat the date using strtotime (with a bit of hacking around maybe to get the right format)
4. run an update for each iteration of the loop and put the new value in your newdate field
5. delete the old date column.
6. rename newdate as appropriate
 
Back
Top Bottom