Bluehost.com Web Hosting $6.95

How to convert a improper date format inside mysql?

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 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-08-2007
DC
 
Posts: n/a
Default How to convert a improper date format inside mysql?

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?

Reply With Quote
  #2 (permalink)  
Old 03-08-2007
Gordon Burditt
 
Posts: n/a
Default Re: How to convert a improper date format inside mysql?

>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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:32 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0