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. Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/ 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. Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392043 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! Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392044 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'; Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392046 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??? Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392047 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']; Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392049 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. Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392050 Share on other sites More sharing options...
axiom82 Posted November 15, 2007 Share Posted November 15, 2007 explain your request in depth Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392052 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! Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392054 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 Link to comment https://forums.phpfreaks.com/topic/77444-solved-strtotime/#findComment-392058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.