# How to save time and compare only the hour & minute part?

**URL:** <https://www.ruby-forum.com/t/how-to-save-time-and-compare-only-the-hour-minute-part/140126>\
**Category:** Rails\
**Created:** [June 11, 2008, 3:44am UTC](https://www.ruby-forum.com/t/how-to-save-time-and-compare-only-the-hour-minute-part/140126 "2008-06-11T03:44:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![melvinram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@melvinram](https://www.ruby-forum.com/u/melvinram)\
**Post date:** [June 11, 2008, 3:44am UTC](https://www.ruby-forum.com/t/how-to-save-time-and-compare-only-the-hour-minute-part/140126/1 "2008-06-11T03:44:32Z")

</div>

My model Enrollment has a time field called delivery\_time. How do I  
set it to 8:00AM?

In my migration, I had it do:

t.time :delivery\_time, :default =\> “8:00AM”

But when I go into the console and output the value of delivery\_time,  
it spits out “Sat Jan 01 08:00:00 +0000 2000”

Why is it doing this?

WHAT I’M TRYING TO DO:

What I want to do is have a condition statement like this:

ModelName.find(:all, :conditions =\> [":delivery\_time = ?",  
Time.now.hour]

---

<div class="post-metadata">

**Author:** ![melvinram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@melvinram](https://www.ruby-forum.com/u/melvinram)\
**Post date:** [June 11, 2008, 4:06am UTC](https://www.ruby-forum.com/t/how-to-save-time-and-compare-only-the-hour-minute-part/140126/2 "2008-06-11T04:06:46Z")

</div>

Here is some context:

My app sends out an email every day to it’s users with some info. When  
the user signs up, they decide what time they want to recieve their  
daily email.

The subscription is managed by a model called Enrollment, which has  
the fields last\_deliver\_date and delivery\_time.

I need to create Enrollment.due that return all enrollments that have  
a last\_delivery\_date older than 1 day and has a delivery\_time that is  
within 1 hr of now

---

<div class="post-metadata">

**Author:** ![melvinram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@melvinram](https://www.ruby-forum.com/u/melvinram)\
**Post date:** [June 11, 2008, 4:26am UTC](https://www.ruby-forum.com/t/how-to-save-time-and-compare-only-the-hour-minute-part/140126/3 "2008-06-11T04:26:03Z")

</div>

On Tue, 2008-06-10 at 19:06 -0700, mel ram wrote:

> a last\_delivery\_date older than 1 day and has a delivery\_time that is
> 
> > But when I go into the console and output the value of delivery\_time,  
> > it spits out “Sat Jan 01 08:00:00 +0000 2000”
> > 
> > Why is it doing this?
> > 
> > WHAT I’M TRYING TO DO:
> > 
> > What I want to do is have a condition statement like this:
> > 
> > ModelName.find(:all, :conditions =\> [":delivery\_time = ?",  
> > Time.now.hour]

* * *

I’m still a bit vague on what you are trying to accomplish overall -  
i.e. is this a one time shot e-mail or will this recycle but anyway…

I would probably have a date field for the sending date and a number  
field for the hour 0…23

and then I would find\_all == hour and run this on an hourly basis  
(gathering what I can from above)

Craig
