# How to set the default year for DateTime.parse

**URL:** <https://www.ruby-forum.com/t/how-to-set-the-default-year-for-datetime-parse/164599>\
**Category:** Ruby\
**Created:** [April 2, 2009, 11:35pm UTC](https://www.ruby-forum.com/t/how-to-set-the-default-year-for-datetime-parse/164599 "2009-04-02T23:35:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [April 2, 2009, 11:35pm UTC](https://www.ruby-forum.com/t/how-to-set-the-default-year-for-datetime-parse/164599/1 "2009-04-02T23:35:50Z")

</div>

I’m running into an odd little issue. I banged out a quick script on  
my laptop (running ubuntu) this afternoon, and moved it over to one of  
my servers (running CentOS 5.2). Even though both have ruby 1.8, I  
ran into an odd inconsistency with DateTime.parse

It looks like on the Ubuntu box, parse just goes ahead and uses the  
current year if none is given. On the CentOS box, it doesn’t and  
errors out.

Ubuntu, ruby 1.8.7  
puts DateTime.parse(“Apr 2 16:30:31”)  
=\>2009-04-02T16:30:31+00:00  
puts DateTime.parse(“Apr 2 2009 16:30:31”)  
=\>2009-04-02T16:30:31+00:00

CentOS, ruby 1.8.5  
puts DateTime.parse(“Apr 2 16:30:31”)  
ArgumentError: 3 elements of civil date are necessary  
from /usr/lib/ruby/1.8/date.rb:1214:in `new_with_hash' from /usr/lib/ruby/1.8/date.rb:1258:in`parse’  
from (irb):2  
puts DateTime.parse(“Apr 2 2009 16:30:31”)  
=\>2009-04-02T16:30:31Z

Thanks  
–Kyle
