December 18, 2004

Americans getting dates backwards

Andrew brings up the subject of dates on the web.

They were grumbling that Americans keep entering dates in their web forms the wrong way round, so an event that's supposed to be recorded as 11/12/04 gets recorded as 12/11/04 … and it's impossible to tell when the month and the day has been transposed.

This is an issue that plagues the web, but it is possible to work around it without resorting to the somewhat ugly "Click three times to enter each date" format that select elements for each component of the date cause.

Start with a text input and an example that encourages unambiguous input:
e.g. 18 December 2004.

When the data reaches the server, check the format to see if it is ambiguous (this is little more then testing to see if it contains two distinct numbers which are less then or equal to twelve).

Due to the example, it hopefully will not be, but if it is, then return it to the user replacing the input with something along the lines of: Did you mean 5th January 2004 or 1st May 2004?.

Otherwise, chuck the data into Date::Parse or similar. This nice little tool can cope with all sorts of different date formats.

That is all you really need, but to make life even easier for users, let them click to enter the date. DynArch's DHTML Calendar is a nice tool that degrades fairly cleanly for this type of thing.

I might spend some time next week throwing up a demo of this in action (Perl source to be available). Then all someone needs to is to add it to their web application framework…

Posted at December 18, 2004 09:23 AM (TrackBack)