What is the correct data type to store "Business Hours"

I am collecting Business Hours from users, the format will look like this:

1:30
0:45
2:15
8:00
6:19

      

In SQL SERVER, what datatype should I use to store this value? I will need to sum this value at some point.

+3


source to share


2 answers


Do not store hours worked, keep minutes worked. Your values ​​will become

Time int
---- ---
1:30 90
0:45 45
2:15 135
8:00 480
6:19 379

      



You will be able to convert it for display if necessary by dividing by 60 and taking the remainder.

Compression, on the other hand, will be very light.

+5


source


SQL Server, unfortunately, doesn't have a data type that represents time slot 1 . I usually suggest a column int

and a bit of naming so that it clears it up in seconds / minutes / hours - no matter what granularity you want.




1 It has a data type time

but represents a time of day, not a time interval. It doesn't make sense to add twice a day together and it does, the datatype time

doesn't support adding.

+4


source







All Articles