How do I get a unix timestamp from PHP date time?

user1216398 picture user1216398 · Oct 9, 2012 · Viewed 36.6k times · Source

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?

Answer

Baba picture Baba · Oct 9, 2012

strtotime Returns a timestamp on success, FALSE otherwise.

 echo strtotime('2012-07-25 14:35:08' );

Output

1343219708