# DateTime is not a Date?

**URL:** <https://www.ruby-forum.com/t/datetime-is-not-a-date/76544>\
**Category:** Ruby\
**Created:** [November 20, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/datetime-is-not-a-date/76544 "2006-11-20T14:45:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sammy\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Sammy\_L](https://www.ruby-forum.com/u/Sammy_L)\
**Post date:** [November 20, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/datetime-is-not-a-date/76544/1 "2006-11-20T14:45:57Z")

</div>

So, I was playing around a little in Ruby and noticed that |DateTime| is  
a subclass of |Date|, yet the method |today| is not defined for it.

I can certainly see how it doesn’t make sense to have that method for  
that class, but I’m wondering why a Date isn’t a DateTime? I suppose  
then we’d be removing the time element, so we’d get the same problem…  
but it was just striking is all.

---

<div class="post-metadata">

**Author:** ![Sammy\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Sammy\_L](https://www.ruby-forum.com/u/Sammy_L)\
**Post date:** [November 20, 2006, 2:47pm UTC](https://www.ruby-forum.com/t/datetime-is-not-a-date/76544/2 "2006-11-20T14:47:21Z")

</div>

On 20.11.2006 00:16, Sammy L. wrote:

> So, I was playing around a little in Ruby and noticed that |DateTime| is  
> a subclass of |Date|, yet the method |today| is not defined for it.

First of all this method is a singleton method of instance Date and  
these are not inherited the same way as instance methods are.  
DateTime.today does not make much sense - after all, what time would you  
expect? Instead there is DateTime.now:

> > Date.methods - DateTime.methods  
> > =\> [“today”]
> 
> > DateTime.methods - Date.methods  
> > =\> [“now”, “valid\_time?”]

> I can certainly see how it doesn’t make sense to have that method for  
> that class, but I’m wondering why a Date isn’t a DateTime? I suppose  
> then we’d be removing the time element, so we’d get the same problem…  
> but it was just striking is all.

A Date cannot be a DateTime because it lacks time. Consequently  
DateTime inherits Date:

> > Date.ancestors  
> > =\> [Date, Comparable, Object, Kernel]
> 
> > DateTime.ancestors  
> > =\> [DateTime, Date, Comparable, Object, Kernel]

Once can certainly argue whether DateTime _is a_ Date or rather _has a_  
Date. But it is definitively clear that Date _is not_ a DateTime simply  
because it does not provide the same set of information that DateTime  
provides (date _and_ time).

Kind regards

```
robert
```
