# DateTime

**URL:** <https://www.ruby-forum.com/t/datetime/79658>\
**Category:** Ruby\
**Created:** [December 17, 2006, 7:39pm UTC](https://www.ruby-forum.com/t/datetime/79658 "2006-12-17T19:39:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@chell](https://www.ruby-forum.com/u/chell)\
**Post date:** [December 17, 2006, 7:39pm UTC](https://www.ruby-forum.com/t/datetime/79658/1 "2006-12-17T19:39:48Z")

</div>

Hi,

I’ve just checked out this: [http://ruby.cenophobie.com/RubyCheat.pdf](http://ruby.cenophobie.com/RubyCheat.pdf)  
Ruby cheat sheet. On the second page, DateTime is mentioned but when I  
try the following:

DateTime::now

or

DateTime.now

it says that the constant DateTime is uninitalized.

Can anyone help?

---

<div class="post-metadata">

**Author:** ![chell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@chell](https://www.ruby-forum.com/u/chell)\
**Post date:** [December 17, 2006, 7:44pm UTC](https://www.ruby-forum.com/t/datetime/79658/2 "2006-12-17T19:44:58Z")

</div>

> it says that the constant DateTime is uninitalized.
> 
> Can anyone help?

Sure. You should add this line:

require â€˜dateâ€™

you can find some more examples on date/time and other simple exercises  
on my blog:

[http://www.rubyrailways.com/implementing-15-exercises-for-learning-a-new-programming-language/](http://www.rubyrailways.com/implementing-15-exercises-for-learning-a-new-programming-language/)

HTH,  
Peter

\_\_  
[http://www.rubyrailways.com](http://www.rubyrailways.com)

---

<div class="post-metadata">

**Author:** ![chell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@chell](https://www.ruby-forum.com/u/chell)\
**Post date:** [December 17, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/datetime/79658/3 "2006-12-17T19:47:34Z")

</div>

Peter S. wrote:

> Sure. You should add this line:
> 
> require â€˜dateâ€™

Thanks a lot, Peter. It works fine now.

---

<div class="post-metadata">

**Author:** ![chell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@chell](https://www.ruby-forum.com/u/chell)\
**Post date:** [December 18, 2006, 12:27am UTC](https://www.ruby-forum.com/t/datetime/79658/4 "2006-12-18T00:27:37Z")

</div>

Hi,

In message “Re: DateTime”  
on Mon, 18 Dec 2006 03:39:50 +0900, Lucas H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|DateTime::now  
|  
|or  
|  
|DateTime.now  
|  
|it says that the constant DateTime is uninitalized.  
|  
|Can anyone help?

Put

require ‘date’

before using DateTime.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![chell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@chell](https://www.ruby-forum.com/u/chell)\
**Post date:** [December 18, 2006, 9:42pm UTC](https://www.ruby-forum.com/t/datetime/79658/5 "2006-12-18T21:42:27Z")

</div>

On 12/18/06, Ayaz Ahmed K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> time?
> 
> –

This older thread might clear up the confusion between DateTime and  
Time:

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/96071](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/96071)

- rob

---

<div class="post-metadata">

**Author:** ![chell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@chell](https://www.ruby-forum.com/u/chell)\
**Post date:** [December 20, 2006, 9:52pm UTC](https://www.ruby-forum.com/t/datetime/79658/6 "2006-12-20T21:52:06Z")

</div>

“Rob S.” typed:

> On 12/18/06, Ayaz Ahmed K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > There is also “Time.now” which, as I see it, does not require any  
> > module(s) to be loaded explicitly by the user. I haven’t checked yet, but  
> > do the two differ in any other way than the format in which they report  
> > time?
> 
> This older thread might clear up the confusion between DateTime and Time:  
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/96071](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/96071)

An insightful explanation. Thanks, Rob.

–  
Ayaz Ahmed K.

It is impossible to defend perfectly against the attack of those who  
want to die.

---

<div class="post-metadata">

**Author:** ![chell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@chell](https://www.ruby-forum.com/u/chell)\
**Post date:** [December 18, 2006, 7:02am UTC](https://www.ruby-forum.com/t/datetime/79658/7 "2006-12-18T07:02:18Z")

</div>

“Lucas H.” typed:

> DateTime::now  
> or  
> DateTime.now
> 
> it says that the constant DateTime is uninitalized.

There is also “Time.now” which, as I see it, does not require any  
module(s) to be loaded explicitly by the user. I haven’t checked yet,  
but  
do the two differ in any other way than the format in which they report  
time?

–  
Ayaz Ahmed K.

It is impossible to defend perfectly against the attack of those who  
want to die.
