I'm trying to get a unix timestamp with PHP but it doesn't seem to be working. Here is the format I'm trying to convert to a unix timestamp:
PHP
$datetime = '2012-07-25 14:35:08';
$unix_time = date('Ymdhis', strtotime($datetime ));
echo $unix_time;
My result looks like this:
20120725023508
Any idea what I'm doing wrong?
To extend the answers here with an object-oriented solution, the DateTime class must be named. The DateTime class is available since PHP 5.2 and can be used as follows.
Or even as a one-liner
strtotime Returns a
timestamp
on success, FALSE otherwise.Output
This is converting it to a unix timestamp:
strtotime($datetime)
, but you're converting it back to a date again withdate()
.