oskare100 Posted January 23, 2007 Share Posted January 23, 2007 Hello,I have one column with dates stored in VARCHAR like this: 14:08:41 Nov 20, 2006.Now I need to move all rows in that table and insert them in another table where I need store the times in the datetime MySQL format.So I need to convert all times like 14:08:41 Nov 20, 2006 into datetime like 0000-00-00 00:00:00. How can I do that?Best Regards Quote Link to comment https://forums.phpfreaks.com/topic/35389-convert-into-datetime-mysql-format/ Share on other sites More sharing options...
simcoweb Posted January 23, 2007 Share Posted January 23, 2007 I believe what you need is this function: strtotime()which converts dates to timestamp format. http://us3.php.net/strtotime Quote Link to comment https://forums.phpfreaks.com/topic/35389-convert-into-datetime-mysql-format/#findComment-167321 Share on other sites More sharing options...
michaellunsford Posted January 23, 2007 Share Posted January 23, 2007 you can try converting the old format to the new using [code=php:0]date("Y-m-d H:i:s",strtotime($oldtimeformat))[/code] -- but don't just feed that to your database. Sometimes strtotime works awesome, sometimes it's not so smart. If it works, great, if not, reply back and we'll do it the hard way.[url=http://us3.php.net/strtotime]strtotime()[/url][url=http://us2.php.net/date]date()[/url] Quote Link to comment https://forums.phpfreaks.com/topic/35389-convert-into-datetime-mysql-format/#findComment-167327 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.