# Comparing datetime

**URL:** <https://www.ruby-forum.com/t/comparing-datetime/148986>\
**Category:** Rails\
**Created:** [September 18, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/comparing-datetime/148986 "2008-09-18T23:19:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [September 18, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/comparing-datetime/148986/1 "2008-09-18T23:19:33Z")

</div>

Hi all,

I have an event containing a datetime and want to see if that datetime  
is in the past.

I have a method in event  
def future\_event?  
if self.start \<= DateTime.now()  
return true  
end  
false  
end

on an event I can the do event.future\_event?

This results in You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.\<=

The strange thing is that self is definatly not nil? Is this a problem  
with DateTime.now()?

regards,  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [September 18, 2008, 11:21pm UTC](https://www.ruby-forum.com/t/comparing-datetime/148986/2 "2008-09-18T23:21:54Z")

</div>

On Sep 18, 10:19 pm, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This results in You have a nil object when you didn’t expect it!  
> The error occurred while evaluating nil.\<=

It’s not telling you that self is nil (which as you point out it isn’t  
usually), it’s telling you that self.start is nil.

Fred

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [September 19, 2008, 9:37am UTC](https://www.ruby-forum.com/t/comparing-datetime/148986/3 "2008-09-19T09:37:15Z")

</div>

self.start indeed returns a nil value but the strange this is that it  
is when I look at the self.attributes -\> start in the debugger it is  
correctly filled in. Is start a name you can’t use in rails?

Regards,  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [September 19, 2008, 11:14am UTC](https://www.ruby-forum.com/t/comparing-datetime/148986/4 "2008-09-19T11:14:09Z")

</div>

On 19 Sep 2008, at 08:36, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> self.start indeed returns a nil value but the strange this is that it  
> is when I look at the self.attributes → start in the debugger it is  
> correctly filled in. Is start a name you can’t use in rails?

Oh, you may be running into an edge case when running under the  
debugger. Old versions of rdebug would define their own start method.

Fred

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [September 19, 2008, 2:37pm UTC](https://www.ruby-forum.com/t/comparing-datetime/148986/5 "2008-09-19T14:37:20Z")

</div>

I changed the name of ‘start’ to ‘begin’ and it works now in debug.

Thanks  
Stijn
