# About time compare

**URL:** <https://www.ruby-forum.com/t/about-time-compare/146542>\
**Category:** Rails\
**Created:** [August 22, 2008, 6:22am UTC](https://www.ruby-forum.com/t/about-time-compare/146542 "2008-08-22T06:22:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [August 22, 2008, 6:22am UTC](https://www.ruby-forum.com/t/about-time-compare/146542/1 "2008-08-22T06:22:58Z")

</div>

I have a submmited date param whose data type is date and want to use  
the Time object and the date param to judge if the date param passes the  
today. I use the following codes judging:  
#########  
date.yday-Time.now.yday\<0  
##########  
But i do not know if this code is right.Anyone tell me?

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [August 22, 2008, 9:16am UTC](https://www.ruby-forum.com/t/about-time-compare/146542/2 "2008-08-22T09:16:07Z")

</div>

On Aug 22, 5:22 am, Guo Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have a submmited date param whose data type is date and want to use  
> the Time object and the date param to judge if the date param passes the  
> today. I use the following codes judging:  
> #########  
> date.yday-Time.now.yday\<0  
> ##########

why not just date \< Time.now ?

Fred

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [August 22, 2008, 10:35am UTC](https://www.ruby-forum.com/t/about-time-compare/146542/3 "2008-08-22T10:35:05Z")

</div>

> why not just date \< Time.now ?
> 
> Fred

I just want to compare the year,month,and day,but Time.now includes the  
miniute

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [August 22, 2008, 12:18pm UTC](https://www.ruby-forum.com/t/about-time-compare/146542/4 "2008-08-22T12:18:57Z")

</div>

On 22 Aug 2008, at 09:35, Guo Y. wrote:

> > why not just date \< Time.now ?
> > 
> > Fred
> 
> I just want to compare the year,month,and day,but Time.now includes  
> the  
> miniute

You could use the to\_date method to compare the actual dates (or use  
change(:hour =\>0) which discard the hour minute and seconds components)

Fred

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [August 22, 2008, 4:13pm UTC](https://www.ruby-forum.com/t/about-time-compare/146542/5 "2008-08-22T16:13:35Z")

</div>

> You could use the to\_date method to compare the actual dates (or use  
> change(:hour =\>0) which discard the hour minute and seconds components)
> 
> Fred

Thank you very much!
