How to make strtotime parse dates in Australian (i.e. UK) format: dd/mm/yyyy?

Posted by Iain Fraser on Stack Overflow See other posts from Stack Overflow or by Iain Fraser
Published on 2010-03-15T02:53:26Z Indexed on 2010/03/15 2:59 UTC
Read the original article Hit count: 355

Filed under:
|
|
|
|

I can't beleive I've never come across this one before.

Basically, I'm parsing the text in human-created text documents and one of the fields I need to parse is a date and time. Because I'm in Australia, dates are formatted like dd/mm/yyyy but strtotime only wants to parse it as a US formatted date. Also, exploding by / isn't going to work because, as I mentioned, these documents are hand-typed and some of them take the form of d M yy.

I've tried multiple combinations of setlocale but no matter what I try, the language is always set to US English.

I'm fairly sure setlocale is the key here, but I don't seem to be able to strike upon the right code. Tried these:

  • au
  • au-en
  • en_AU
  • australia
  • aus

Anything else I can try?

Thanks so much :)

Iain

Example:

$mydatetime = strtotime("9/02/10 2.00PM");
echo date('j F Y H:i', $mydatetime);

Produces

2 September 2010 14:00

I want it to produce:

9 February 2010 14:00

© Stack Overflow or respective owner

Related posts about php

Related posts about locale