eon201 Posted November 15, 2007 Share Posted November 15, 2007 Hi, Im trying to use the strtotime function to convert this a date in this format ( 2007 11 11 20:34:56 ) to a unix timestamp. It should work (I think) but doesnt. What have I done wrong with the below code?? $date = strtotime($date); Thanks in advance. Eon201. Quote Link to comment Share on other sites More sharing options...
trq Posted November 15, 2007 Share Posted November 15, 2007 Where do you define $date? Post more code. Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 15, 2007 Author Share Posted November 15, 2007 lol. sorry so date in the array is in this format yyyy-mm-dd whilst time is in this format hh:mm:ss $time = $overall_array['time']; $date = $overall_array['date']; $date = $date. " ". $time; $date = substr_replace($date, " ", 4, 1); $date = substr_replace($date, " ", 7, 1); $date = '2007 11 11 20:34:56'; Hope that helps clear things up! Quote Link to comment Share on other sites More sharing options...
Barand Posted November 15, 2007 Share Posted November 15, 2007 needs to be $date = '2007-11-11 20:34:56'; Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 15, 2007 Author Share Posted November 15, 2007 oh I thought that I haid to strip the "-" and replace tem with " " for the strtotime function to work??? Quote Link to comment Share on other sites More sharing options...
axiom82 Posted November 15, 2007 Share Posted November 15, 2007 MySQL has a unix_timestamp() function that will convert a MySQL datetime format to a unix_timestamp like this... $query = mysql_query ("SELECT unix_timestamp('2007-11-15 12:00:00') AS timestamp"); $date = mysql_fetch_assoc ($query); echo $date['timestamp']; The parameter of the function can also be a database field like this... $query = mysql_query ("SELECT unix_timestamp(date) AS timestamp"); $date = mysql_fetch_assoc ($query); echo $date['timestamp']; Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 15, 2007 Author Share Posted November 15, 2007 yes. But thats not unfortunatly what im trying to achieve. Quote Link to comment Share on other sites More sharing options...
axiom82 Posted November 15, 2007 Share Posted November 15, 2007 explain your request in depth Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks Barand thats fixed it for me! Thankyou axiom82 but the problem is now solved. Nice one for trying to help! Quote Link to comment Share on other sites More sharing options...
Barand Posted November 15, 2007 Share Posted November 15, 2007 Some date string formats work, some don't. See this code snippet http://www.phpfreaks.com/forums/index.php/topic,166174.msg731451.html#msg731451 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.