For example, if I want to store the amount of hours a service takes to complete such as... 1 hour of consulting 2 hours of consulting 3 hours of consulting 1 hour swedish massage 1.5 hours swedish massage If it was all whole hours I could just use integer, but note I also need it for half hours. TABLE: services name:string duration: ??? I tried using time, but since my development database is sqlite3, the datatype it uses it''s datetime and stores the current date. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2010-Oct-05 21:11 UTC
Re: What is the best column time to store amount of hours
On 5 October 2010 22:06, Leonel Leonel <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> If it was all whole hours I could just use integer, but note I also need > it for half hours.Store minutes, and use an integer field? In your model divide by 60 in the getter, and multiply by 60 in the setter (or expect minutes as the parameter) to give you the hours (and this lets you easily do quarter-hour increments when the feature-creep comes ;-) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Oct-05 21:12 UTC
Re: What is the best column time to store amount of hours
Leonel Leonel wrote:> For example, if I want to store the amount of hours a service takes to > complete such as... > > 1 hour of consulting > 2 hours of consulting > 3 hours of consulting > > 1 hour swedish massage > 1.5 hours swedish massage > > If it was all whole hours I could just use integer, but note I also need > it for half hours. > > TABLE: services > name:string > duration: ??? > > I tried using time, but since my development database is sqlite3, the > datatype it uses it''s datetime and stores the current date.But your production database won''t be SQLite, because SQLite is unsuitable for production. In any case, there''s nothing wrong with storing times in a datetime field and disregarding the date. However, that''s not what you need here. You''re storing time *intervals*, not clock times. And you yourself spoke of "1.5 hours" above. That suggests that a float or decimal type is what you want. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Leonel *-*
2010-Oct-06 13:13 UTC
Re: What is the best column time to store amount of hours
I guess you guys are right. I wanted to avoid the conversation if possible but your suggestions seem to be the way to go. Thanks :) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.