# Time::parse in ruby 1.9 with mm/dd/yyyy

**URL:** <https://www.ruby-forum.com/t/time-parse-in-ruby-1-9-with-mm-dd-yyyy/147718>\
**Category:** Ruby\
**Created:** [September 4, 2008, 5:24pm UTC](https://www.ruby-forum.com/t/time-parse-in-ruby-1-9-with-mm-dd-yyyy/147718 "2008-09-04T17:24:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Cain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Jim\_Cain](https://www.ruby-forum.com/u/Jim_Cain)\
**Post date:** [September 4, 2008, 5:24pm UTC](https://www.ruby-forum.com/t/time-parse-in-ruby-1-9-with-mm-dd-yyyy/147718/1 "2008-09-04T17:24:35Z")

</div>

In ruby 1.8, for dates in format mm/dd/yyyy, I get this:

$ ruby -rparsedate -e ‘p ParseDate.parsedate(“09/01/2008”)’  
[2008, 9, 1, nil, nil, nil, nil, nil]  
$ ruby -rtime -e ‘p Time.parse(“9/1/2008”)’  
Mon Sep 01 00:00:00 -0400 2008

but in 1.9, I get this:

$ ruby19 -rtime -e ‘p Time.parse(“9/1/2008”)’  
2008-01-09 00:00:00 -0500

Of course 9/1 is ambiguous, but even for a non-ambiguous date, 1.9  
actually gives an error:

$ ruby -rtime -e ‘p Time.parse(“09/15/2008”)’  
Mon Sep 15 00:00:00 -0400 2008  
$ ruby19 -rtime -e ‘p Time.parse(“09/15/2008”)’  
/usr/local/lib/ruby/1.9.0/time.rb:184:in `local': argument out of range (ArgumentError) from /usr/local/lib/ruby/1.9.0/time.rb:184:in`make\_time’  
from /usr/local/lib/ruby/1.9.0/time.rb:243:in `parse' from -e:1:in`’

Is there any way I can easily tell Time::parse to favor mm/dd/yyyy  
over dd/mm/yyyy? I can’t use strptime because I have no idea what  
format the dates are in. Also, I don’t want to have to write code to  
figure out the format first, since that would mean I’m essentially  
writing my own Time::parse.

Cheers,  
Jim

---

<div class="post-metadata">

**Author:** ![Jim\_Cain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Jim\_Cain](https://www.ruby-forum.com/u/Jim_Cain)\
**Post date:** [September 5, 2008, 1:37am UTC](https://www.ruby-forum.com/t/time-parse-in-ruby-1-9-with-mm-dd-yyyy/147718/2 "2008-09-05T01:37:16Z")

</div>

Oh, here is some output of Date::\_parse directly:

$ ruby -w -rdate -e ‘p Date.\_parse(“12/31/75 21:28:35”, true)’  
{:sec=\>35, :year=\>1975, :hour=\>21, :mday=\>31, :min=\>28, :mon=\>12}  
$ ruby19 -w -rdate -e ‘p Date.\_parse(“12/31/75 21:28:35”, true)’  
{:hour=\>21, :min=\>28, :sec=\>35, :year=\>2012, :mon=\>31, :mday=\>75}

month == 31? mday == 75? Really??

Cheers,  
Jim
