# Date.parse 1.8 vs 1.9

**URL:** <https://www.ruby-forum.com/t/date-parse-1-8-vs-1-9/165545>\
**Category:** Ruby\
**Created:** [April 15, 2009, 2:39am UTC](https://www.ruby-forum.com/t/date-parse-1-8-vs-1-9/165545 "2009-04-15T02:39:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 15, 2009, 2:39am UTC](https://www.ruby-forum.com/t/date-parse-1-8-vs-1-9/165545/1 "2009-04-15T02:39:44Z")

</div>

In attempting to make a small library of mine 1.9 compatible I have  
run across an inconsistency in date parsing.

Ruby 1.8:

> > puts Date.parse(“4/12/2009”)  
> > 2009-04-12

> > puts Date.parse(“4/30/2009”)  
> > 2009-04-30

Ruby 1.9:

> > puts Date.parse(“4/12/2009”)  
> > 2009-12-04

> > puts Date.parse(“4/30/2009”)  
> > ArgumentError: invalid date

I am sure I am not the first person to run across this issue. What is  
the recommended way for dealing with this?

Best,  
Michael G.

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 15, 2009, 3:44am UTC](https://www.ruby-forum.com/t/date-parse-1-8-vs-1-9/165545/2 "2009-04-15T03:44:04Z")

</div>

On Apr 14, 2009, at 8:39 PM, Michael G. wrote:

> Ruby 1.9:  
> Michael G.

Probably with Date.strptime rather than Date.parse so you can specify  
a format. I’m not actually that surprised by the 04-12 v. 12-04 since  
the docs say that there are heuristics, but 4/30/2009 ought to be  
unambiguous as 2009 can’t be a month or a day and 30 can’t be a month.

$ macirb  
irb\> require ‘date’  
=\> true  
irb\> puts Date.parse(“4/30/2009”)  
ArgumentError: invalid date  
from /Library/Frameworks/MacRuby.framework/Versions/0.3/usr/lib/ruby/  
1.9.0/date.rb:1023:in `new_by_frags' from /Library/Frameworks/MacRuby.framework/Versions/0.3/usr/lib/ruby/ 1.9.0/date.rb:1067:in `parse’  
from (irb):2  
from /usr/local/bin/macirb:12:in `’  
irb\> puts Date.strptime(“4/30/2009”, “%m/%d/%Y”)  
2009-04-30  
=\> nil  
irb\> RUBY\_VERSION  
=\> “1.9.0”

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 15, 2009, 3:55am UTC](https://www.ruby-forum.com/t/date-parse-1-8-vs-1-9/165545/3 "2009-04-15T03:55:19Z")

</div>

On Tue, Apr 14, 2009 at 9:43 PM, Rob B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 2009-04-12
> 
> ArgumentError: invalid date  
> =\> nil  
> irb\> RUBY\_VERSION  
> =\> “1.9.0”

Thanks Rob! If you would have came to Cincinnati.rb tonight you could  
have told me in person. 🙂

Michael G.

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 15, 2009, 4:37am UTC](https://www.ruby-forum.com/t/date-parse-1-8-vs-1-9/165545/4 "2009-04-15T04:37:33Z")

</div>

> > > puts Date.parse(“4/30/2009”)  
> > > ArgumentError: invalid date
> 
> I am sure I am not the first person to run across this issue. What is  
> the recommended way for dealing with this?

[http://redmine.ruby-lang.org/issues/show/634](http://redmine.ruby-lang.org/issues/show/634)  
treats to some background of it. But doesn’t explain this oddity  
[unless it is just Ruby saying “you are running into danger by even  
attempting to parse dd/dd/dddd because the first two dd’s could  
theoretically later come back to bite you” [?]

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 15, 2009, 11:30am UTC](https://www.ruby-forum.com/t/date-parse-1-8-vs-1-9/165545/5 "2009-04-15T11:30:38Z")

</div>

Roger P. wrote:

> [http://redmine.ruby-lang.org/issues/show/634](http://redmine.ruby-lang.org/issues/show/634)  
> treats to some background of it. But doesn’t explain this oddity  
> [unless it is just Ruby saying “you are running into danger by even  
> attempting to parse dd/dd/dddd because the first two dd’s could  
> theoretically later come back to bite you” [?]

It would be silly if 4/30/2009 were parsed as m=4,d=30,y=2009  
but 4/5/2009 were parsed as d=4,m=5,y=2009

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 15, 2009, 4:46am UTC](https://www.ruby-forum.com/t/date-parse-1-8-vs-1-9/165545/6 "2009-04-15T04:46:10Z")

</div>

On Wed, Apr 15, 2009 at 8:39 AM, Michael G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am sure I am not the first person to run across this issue. What is

fwiw, i prefer current ruby1.9 behaviour primarily because

Date.parse(“2009/4/30”) == Date.parse(“30/4/2009”) #=\>true

thus, i do not have this issue since i always enter dates strings in  
yyyy/mm/dd or dd/mm/yyyy format

kind regards -botp
