# DateTime confusion

**URL:** <https://www.ruby-forum.com/t/datetime-confusion/117059>\
**Category:** Ruby\
**Created:** [October 12, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/datetime-confusion/117059 "2007-10-12T16:16:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 12, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/datetime-confusion/117059/1 "2007-10-12T16:16:38Z")

</div>

Hello!  
Wondered if anyone could help…  
I’m trying to parse a datetime

date = DateTime.parse(“200701011900”)

Which gives me a datetime. When i print it, it gives:  
2007-01-01T19:00:00+00:00=\> nil

but when I try:

print date.year

it gives me an unknown method error… any ideas what I’m doing  
wrong?

Cheers!  
Chris

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 12, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/datetime-confusion/117059/2 "2007-10-12T17:44:14Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Hello!  
> Wondered if anyone could help…  
> I’m trying to parse a datetime
> 
> date = DateTime.parse(“200701011900”)
> 
> Which gives me a datetime. When i print it, it gives:  
> 2007-01-01T19:00:00+00:00=\> nil
> 
> but when I try:
> 
> print date.year
> 
> it gives me an unknown method error… any ideas what I’m doing  
> wrong?
> 
> Cheers!  
> Chris

It works fine for me, although I wouldn’t name the variable ‘date’ since  
it is the same name as the file you are including.

require ‘date’

date = DateTime.parse(“200701011900”)  
puts date.year

–output:–  
2007

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 12, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/datetime-confusion/117059/3 "2007-10-12T18:10:30Z")

</div>

On 12 Oct, 14:39, “removed\_email\_address@domain.invalid”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> print date.year
> 
> it gives me an unknown method error… any ideas what I’m doing  
> wrong?
> 
> Cheers!  
> Chris

Don’t worry guys, just being an idiot!  
Cheers
