How to JUST store hours and minutes in db?

I have a table for “restaurants” and need to store their weekly hours of
operation. I am having trouble finding the best way to do this. I dont
want to use a datetime field because I don’t need the date. I also want
to be able to run queries and find all restaurants that are open at a
given time. Any ideas on how to just store the time? Thanks for your
help.

Why can’t you just store the time as a string? I believe if you use
datetime field you can format it for just the time.

On Dec 26, 12:02 pm, Ben J. [email protected]
wrote:

I have a table for “restaurants” and need to store their weekly hours of
operation. I am having trouble finding the best way to do this. I dont
want to use a datetime field because I don’t need the date. I also want
to be able to run queries and find all restaurants that are open at a
given time. Any ideas on how to just store the time? Thanks for your
help.

I would use a decimal field so 8:00 AM (0800) would be 8.0 and 4:30 PM
(1630) would be 16.5.

AFAIK, there is no plugin to do this, but it shouldn’t be a difficult
coding process.

Um… what is wrong with using a TIME field?


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

On Dec 26, 5:17 pm, “Ryan B.” [email protected] wrote:

Um… what is wrong with using a TIME field?

Ryan is correct.

In your migration

create_table “products” do |t|
t.column “opening_time”, :time
t.column “closing_time”, :time
end

–or in Rails 2–

create_table “products” do |t|
t.time “opening_time”, “closing_time”
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs