anujgarg Posted October 1, 2008 Share Posted October 1, 2008 I am trying to convert a date string to TimeStamp. Means, 2008-08-20 00:00:00 to 456733800 (say) Should I use strtotime for this? I am not getting the desired result? Please help Link to comment https://forums.phpfreaks.com/topic/126573-conerting-date-to-timestamp/ Share on other sites More sharing options...
hawkenterprises Posted October 1, 2008 Share Posted October 1, 2008 I use this function to do it for me function mysql2timestamp($datetime){ $val = explode(" ",$datetime); $date = explode("-",$val[0]); $time = explode(":",$val[1]); return mktime($time[0],$time[1],$time[2],$date[1],$date[2],$date[0]); } Link to comment https://forums.phpfreaks.com/topic/126573-conerting-date-to-timestamp/#findComment-654599 Share on other sites More sharing options...
thebadbad Posted October 1, 2008 Share Posted October 1, 2008 strtotime() will do it. What are you getting? Link to comment https://forums.phpfreaks.com/topic/126573-conerting-date-to-timestamp/#findComment-654626 Share on other sites More sharing options...
PFMaBiSmAd Posted October 1, 2008 Share Posted October 1, 2008 And since you are likely getting this from a database, just use the mysql UNIX_TIMESTAMP(your_date_column) function in your SELECT query. No need for any slow parsed/tokenized/interpreted php code at all. Link to comment https://forums.phpfreaks.com/topic/126573-conerting-date-to-timestamp/#findComment-654695 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.