tags:

views:

140

answers:

3

I've a date like Tue Dec 15 2009. How can I convert it into seconds?

+10  A: 

I assume by seconds you mean a UNIX timestamp.

strtotime() should help.

Pekka
Yeah, UNIX timestamp! that's what i Meant. Thanks for the help
baltusaj
+3  A: 

You mean like an UNIX-timestamp? Try:

echo strtotime('Tue Dec 15 2009');
Hanse
Thanks a lot Hanse
baltusaj
+5  A: 

You can use the strtotime function to convert that date to a timestamp :

$str = 'Tue Dec 15 2009';
$timestamp = strtotime($str);

And, just to be sure, let's convert it back to a date as a string :

var_dump(date('Y-m-d', $timestamp));

Which gives us :

string '2009-12-15' (length=10)

(Which proves strtotime did understand our date ^^ )

Pascal MARTIN
Many thanks Martin. Liked your verification part. :)
baltusaj
@Usman : you're welcome :-) ;; well, I've sometimes have had bad surprises with strtotime (especially because I'm french and our dates format is not the same than the english one), so I prefer being careful ^^
Pascal MARTIN