jeffmorris81 Posted March 18, 2011 Share Posted March 18, 2011 Hi, I have time and date stored in variables in the following format... 08:00AM and 03/07/2011 How do I go about converting those, to yyyy-mm-dd hh:mm:ss format.. to then insert into a sql table... Any help would be appreciated thank you.. jeff Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 18, 2011 Share Posted March 18, 2011 The php functions date() and strtotime() will do the trick, or just strtotime() and MySQL's FROM_UNIXTIME() function. $time = "08:00AM"; $date = "03/07/2011"; $formatted = date('Y-m-d H:i:s', strtotime("$date $time")); echo $formatted; // use $formatted in query string OR $time = "08:00AM"; $date = "03/07/2011"; $timestamp = strtotime("$date $time"); $query = "INSERT INTO table ( time ) VALUES ( FROM_UNIXTIME($timestamp) )"; Quote Link to comment 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.