Sunday, March 18, 2012

Problem with strtotime in PHP

Today I found an interesting issue. Please try this following PHP code:
print strtotime("18/03/2012 06:08 am");
I didn't see any output. Then I looked at the documentation and found the following line:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

So I had to replace "/" with "-" using str_replace and that worked!
print strtotime("18-03-2012 06:08 am");
Output:
1332029280

No comments: