talideon.com

Blackout Ireland

May 2, 2007 at 3:02PM strtotime(), or why American date formats are retarded

Americans: I’d swear they go out of their way to be awkward.

The particular bit of awkwardness that bit me was PHP’s strtotime(). It’s quite useful but in one regard it’s a bit dumb: it doesn’t seem to bother checking what the current locale is.

Where this is a problem is when you’re typing in dates like 1/12/1979. Now kids, is that December 1st or January 12th? As far as strtotime() is concerned, it’s January 12th, which is fine if you’re American, but for the rest of the English speaking world who also use slashes as date field separators, December 1st. Something of an inconvenience, eh? If you want to get the behaviour the rest of the world uses, you need to use hyphens instead. Aaarrgh!

[Of course, I patched around this with a quick str_replace() to replace any slashes with hyphens. It’s a hack, but at least now it works consistently.]