# Date.new.to\_time.to\_i

**URL:** <https://www.ruby-forum.com/t/date-new-to-time-to-i/170564>\
**Category:** Rails\
**Created:** [June 19, 2009, 1:37am UTC](https://www.ruby-forum.com/t/date-new-to-time-to-i/170564 "2009-06-19T01:37:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [June 19, 2009, 1:37am UTC](https://www.ruby-forum.com/t/date-new-to-time-to-i/170564/1 "2009-06-19T01:37:21Z")

</div>

What’s going on here!?

> > Date.new.to\_time.to\_i  
> > NoMethodError: undefined method `to\_i’ for Mon, 01 Jan -4712 00:00:00  
> > -0800:DateTime  
> > from (irb):25
> 
> > Date.today.to\_time.to\_i  
> > =\> 1245308400

> > RUBY\_VERSION  
> > =\> “1.8.7”
> 
> > Rails.version  
> > =\> “2.1.1”

(I’m not sure if this is a rails thing, or just a ruby thing)

---

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [June 19, 2009, 1:46am UTC](https://www.ruby-forum.com/t/date-new-to-time-to-i/170564/2 "2009-06-19T01:46:37Z")

</div>

If you look at the classes returned, Date.new.to\_time returns a  
DateTime,  
while Date.today.to\_time returns a Time

Date.new.to\_time.class --\> DateTime  
Date.today.to\_time.class --\> Time

Not sure why that is the case, but obviously DateTime doesn’t have a  
to\_i  
method.

Simon

On Fri, 19 Jun 2009 07:37:21 +0800, Michael Economy

---

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [June 19, 2009, 1:56am UTC](https://www.ruby-forum.com/t/date-new-to-time-to-i/170564/3 "2009-06-19T01:56:33Z")

</div>

On Jun 19, 12:45 am, “Simon M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Not sure why that is the case, but obviously DateTime doesn’t have a to\_i  
> method.

Date::new() returns Julian day 0, which is Mon, 01 Jan -4712

to\_time() is a CoreExtensions method which uses Time::utc\_time() →   
Time::time\_with\_datetime\_fallback() from CoreExtensions to generate  
the Time object. From the documentation:

Returns a new Time if requested year can be accommodated by Ruby‘s  
Time class (i.e., if year is within either 1970..2038 or 1902..2038,  
depending on system architecture); otherwise returns a DateTime

Because the year is out of range, you’ll get a DateTime back, which  
you can’t call to\_i on.

This is actually quite silly, when you think about it.

-Matt

---

<div class="post-metadata">

**Author:** ![magic6435](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@magic6435](https://www.ruby-forum.com/u/magic6435)\
**Post date:** [June 19, 2009, 2:43am UTC](https://www.ruby-forum.com/t/date-new-to-time-to-i/170564/4 "2009-06-19T02:43:15Z")

</div>

Ok, now it makes sense. 🙂

(I so hope i can retire before 2038)
