Alex Rivera | Logout

How to convert date to timestamp in PHP?

Asked 2008-09-22T08:41:20.100
394

How do I get timestamp from e.g. 22-09-2008?

Edit
Report

1 Answer

116

Be careful with functions like strtotime() that try to "guess" what you mean (it doesn't guess of course, the rules are here).

Indeed 22-09-2008 will be parsed as 22 September 2008, as it is the only reasonable thing.

How will 08-09-2008 be parsed? Probably 09 August 2008.

What about 2008-09-50? Some versions of PHP parse this as 20 October 2008.

So, if you are sure your input is in DD-MM-YYYY format, it's better to use the solution offered by @Armin Ronacher.

answered 2008-09-22T16:22:12.317

Your Answer