# Checking to see if a day/hour/whatever has passed

**URL:** <https://www.ruby-forum.com/t/checking-to-see-if-a-day-hour-whatever-has-passed/124327>\
**Category:** Rails\
**Created:** [December 27, 2007, 6:32pm UTC](https://www.ruby-forum.com/t/checking-to-see-if-a-day-hour-whatever-has-passed/124327 "2007-12-27T18:32:03Z")\
**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:** [December 27, 2007, 6:32pm UTC](https://www.ruby-forum.com/t/checking-to-see-if-a-day-hour-whatever-has-passed/124327/1 "2007-12-27T18:32:03Z")

</div>

I want to check if an hour has passed since the current time. When I  
run  
return (DateTime.now \> (@session[‘user’].account\_info.last\_reward +  
0.04))

it returns the correct value I think, but when I put that same thing  
(without the return) in an if statement, it tells me it can’t compare  
a datetime and a time. Not sure how to compare them then…

---

<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:** [December 27, 2007, 6:37pm UTC](https://www.ruby-forum.com/t/checking-to-see-if-a-day-hour-whatever-has-passed/124327/2 "2007-12-27T18:37:55Z")

</div>

On 12/27/07, Mike C [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to check if an hour has passed since the current time. When I  
> run  
> return (DateTime.now \> (@session[‘user’].account\_info.last\_reward +  
> 0.04))
> 
> it returns the correct value I think, but when I put that same thing  
> (without the return) in an if statement, it tells me it can’t compare  
> a datetime and a time. Not sure how to compare them then…

You have to convert one to the other’s same class.

> > DateTime.now.class  
> > =\> DateTime

What does this say?

(@session[‘user’].account\_info.last\_reward + 0.04).class

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<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:** [December 28, 2007, 4:34am UTC](https://www.ruby-forum.com/t/checking-to-see-if-a-day-hour-whatever-has-passed/124327/3 "2007-12-28T04:34:02Z")

</div>

I think that would be Time…thanks!
