This is a discussion on How to convert a improper date format inside mysql? within the MySQL Database forums, part of the Database Forums category; So I'm working with a database of crime incidents, and the police department for whatever reason put the datefield ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
So I'm working with a database of crime incidents, and the police
department for whatever reason put the datefield as "1/1/2005 0:00:00" I've left the field as varchar since just changing the fieldtype to datetime doesn't appear to work. I know how to deal with this in PHP...but what kind of functions does mysql have for converting a string into a proper date? Or is my best route to run a php script, in which i read a row, extract the date and convert it, and then update that row? |
|
|||
|
>So I'm working with a database of crime incidents, and the police
>department for whatever reason put the datefield as "1/1/2005 0:00:00" > >I've left the field as varchar since just changing the fieldtype to >datetime doesn't appear to work. > >I know how to deal with this in PHP...but what kind of functions does >mysql have for converting a string into a proper date? Or is my best Try str_to_date(). However, you have to know the format being used. >route to run a php script, in which i read a row, extract the date and >convert it, and then update that row? str_to_date() can probably handle any one of these formats, but you're in trouble if the input is a mixture of them: 2/29/2005 0:00:00 29/2/2005 0:00:00 29-Feb-2005 0:00:00 12:00 AM Feb 29 2005 |