talideon.com

HEEEEEEEEEEELP! I’M COVERED IN BEEEEEEEEEEEES!

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.]

Technorati Search Technorati Search Irish Bloggers

Comments

No comments.

Post a comment

All form information is optional, but it’s a good idea to fill in your name and email address if you want me to take your comment seriously.

Spammers, don’t bother posting crap down here. The site is set up so that legitimate search engines (Google, for instance) won’t index pages with comments on them. Posting crud here only means you’re wasting my time and patience. Shoo!

Real names, please. Please include!
Won’t be displayed. Please include!
Displayed, if present.