# What is the best column time to store amount of hours

**URL:** <https://www.ruby-forum.com/t/what-is-the-best-column-time-to-store-amount-of-hours/196040>\
**Category:** Rails\
**Created:** [October 5, 2010, 11:06pm UTC](https://www.ruby-forum.com/t/what-is-the-best-column-time-to-store-amount-of-hours/196040 "2010-10-05T23:06:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/4491bb/32.png) [@leonel](https://www.ruby-forum.com/u/leonel)\
**Post date:** [October 5, 2010, 11:06pm UTC](https://www.ruby-forum.com/t/what-is-the-best-column-time-to-store-amount-of-hours/196040/1 "2010-10-05T23:06:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![leonel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/4491bb/32.png) [@leonel](https://www.ruby-forum.com/u/leonel)\
**Post date:** [October 5, 2010, 11:12pm UTC](https://www.ruby-forum.com/t/what-is-the-best-column-time-to-store-amount-of-hours/196040/2 "2010-10-05T23:12:47Z")

</div>

On 5 October 2010 22:06, Leonel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 😉

---

<div class="post-metadata">

**Author:** ![leonel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/4491bb/32.png) [@leonel](https://www.ruby-forum.com/u/leonel)\
**Post date:** [October 5, 2010, 11:12pm UTC](https://www.ruby-forum.com/t/what-is-the-best-column-time-to-store-amount-of-hours/196040/3 "2010-10-05T23:12:52Z")

</div>

Leonel L. 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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![leonel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/4491bb/32.png) [@leonel](https://www.ruby-forum.com/u/leonel)\
**Post date:** [October 6, 2010, 3:13pm UTC](https://www.ruby-forum.com/t/what-is-the-best-column-time-to-store-amount-of-hours/196040/4 "2010-10-06T15:13:14Z")

</div>

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 🙂
