Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does date parsing depend on separators?

Tags:

date

ruby

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?

like image 338
Andrew Vit Avatar asked Feb 25 '26 08:02

Andrew Vit


1 Answers

"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

like image 193
vartec Avatar answered Feb 26 '26 22:02

vartec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!