PHP - Using strtotime with a UK date format (dd-mm-yy)

Nick picture Nick · Nov 12, 2010 · Viewed 16.1k times · Source

Quite simply in PHP I have a date of 8th January 2011, in the format 08-01-11 - when I run this into strtotime and convert it back into a different date format, it reverts back to 1st August 2011 - not ideal!

Is there any easy way around this, rather than having to place everything into different arrays/variables and back again?

Thank you!

Answer

myshadowself picture myshadowself · Jan 14, 2013

The perfect solution would be for the US to use the correct date format in the first place... ;0)

I do this to get around it:

$date = "31/12/2012";
$bits = explode('/',$date);
$date = $bits[1].'/'.$bits[0].'/'.$bits[2];

$date is now strtotimeable