I am collecting the Worked Hours from users, the format will be like:
1:30
0:45
2:15
8:00
6:19
In SQL SERVER, what kinda of datatype should I use to store that value? I will need to sum this value in some point.
Do not store worked hours, store worked minutes. Your values would 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 to display as necessary by dividing by 60 and taking the remainder.
Summing, on the other hand, will be very easy.
SQL Server unfortunately doesn't have a data type that represents a time span1. I would normally suggest an int
column and a bit of naming so that it's clear that it's in seconds/minutes/hours - whatever the granularity is that you require.
1It has a time
data type but that represents a time of day, not a time span. It doesn't make sense to add two times of day together, and this being so, the time
data type doesn't support addition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With