UK dates and strtotime

In PHP, strtotime cannot parse the UK date format (i.e. 30/02/2011) as there’s no 30th month.

Here’s a quick fix I came across that seems to work for me (so far)… Just replace the “/” with a “-” before parsing with strtotime.

$timestamp = strtotime(str_replace('/', '-', '30/02/2011'));

Credit goes to Stefan Kunstmann.

Update:

Here’s the note relating to this on php.net…

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 looks like replacing the slash with a dash is the reliable and correct thing to do.

Leave a Reply

Your email address will not be published. Required fields are marked *