Hi, can anyone advise how i would convert a date like "Tuesday, 22 June, 2010 00:00" to a unix timestamp using strtotime()? I need to also store the hours and minutes and it's not clear if is best done using strtotime. Thanks for any help!
strtotime() does convert both date and time. It converts a string to a Unix timestamp.
What is the unix time stamp?
The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch. This is very useful to computer systems for tracking and sorting dated information in dynamic and distributed applications both online and client side.
You can convert a unix timestamp back to a string using date
strtotime and date can be used to convert to a UNIX timestamp and extract portions of that timestamp respectively.
The combination should do what you need.
Due to the second ,, strtotime() will currently not understand your date/time format (remove it and it will work properly).
If you have a static format for the date, using strptime() or DateTime::createFromFormat() are more reliable, and will allow other non-datetime strings in the date to be present as long as you've defined them.
echo DateTime::createFromFormat("l, j F, Y H:i","Tuesday, 22 June, 2010 00:00")->format("c");
$string = "Tuesday, 22 June, 2010 00:00";
$dateString = substr($string,0,-5);
$timeArray = explode(':',substr($string,-5));
$timeStamp = strtotime($dateString) + 60*$timeArray[0] + $timeArray[1];