tags:

views:

255

answers:

2

Take the two following examples:

Date.parse("02/20/2009")
Date.parse("02-20-2009")

In the first example, the order is assumed to be MM DD YYYY, but in the second example an error is raised because (I'm assuming) it tries to parse it as DD MM YYYY.

Why?

A: 

Different locales use different separators in their dates, and different orders for the parts (year, month, day). Ruby passes the date string to a number of functions that progressively attempt to parse it based on the separators.

Ignacio Vazquez-Abrams
+10  A: 

"02/20/2009" is the date representation only in *en_US* locale. "02-20-2009" is not, thus assumed to follow a standard. There are two popular standards, used most everywhere except for the US: DD-MM-YYYY or the ISO 8601, which is YYYY-MM-DD.

http://en.wikipedia.org/wiki/File:Date.png

vartec