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 Link to comment https://forums.phpfreaks.com/topic/231041-time-issue-regex-or-sql/ 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) )"; Link to comment https://forums.phpfreaks.com/topic/231041-time-issue-regex-or-sql/#findComment-1189332 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.