简体   繁体   English

存储“工作时间”的正确数据类型是什么

[英]What is the correct datatype to store “Worked Hours”

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? 在SQL SERVER中,我应该使用哪种数据类型来存储该值? 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. 您可以将其转换为必要时显示,除以60并取余数。

Summing, on the other hand, will be very easy. 另一方面,总结将非常容易。

SQL Server unfortunately doesn't have a data type that represents a time span 1 . 遗憾的是,SQL Server没有表示时间跨度 1的数据类型。 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. 我通常会建议使用int列和一些命名,以便明确表示它是以秒/分钟/小时为单位 - 无论您需要什么样的粒度。


1 It has a time data type but that represents a time of day, not a time span. 1它具有time数据类型,但表示一天中的时间,而不是时间跨度。 It doesn't make sense to add two times of day together, and this being so, the time data type doesn't support addition. 一起添加两次是没有意义的,这样, time数据类型不支持添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM