swtlbee Posted December 9, 2009 Share Posted December 9, 2009 I have taken over a PHP Application/Database(MySQL), the database has a field that dates are entered into and that field is currently a varchar(50) datatype. I need to change the field to a datetime datatype for search functionality purposes. The way the data was entered originally was July 14, 2008 etc. there are over 700 records in the DB but not more than 1000. Is there an easy way to write a quick conversion script and run it against the DB? If so can some one help me out with the script or point me in the right direction to learn how to write the script. Thanks in advance for your response... Quote Link to comment https://forums.phpfreaks.com/topic/184499-convert-varchar-to-datetime-data-type/ Share on other sites More sharing options...
rajivgonsalves Posted December 9, 2009 Share Posted December 9, 2009 you can use STR_TO_DATE function, to convert them to proper date format then you will be able to change your field type select STR_TO_DATE('July 14, 2008', '%M %d,%Y'); Quote Link to comment https://forums.phpfreaks.com/topic/184499-convert-varchar-to-datetime-data-type/#findComment-973949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.