在sql server中存储持续时间(timespans) [英] storing durations (timespans) in sql server

查看:1087
本文介绍了在sql server中存储持续时间(timespans)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在SQL Server 2008数据库中存储持续时间。这通常是如何做的?

I have to store a duration in a SQL Server 2008 database. How is this usually done?

例如,我将能够存储像5分钟,8小时,10天等值。

For example I will have to be able to store values like: 5 minutes, 8 hours, 10 days, etc.

我想把它存储在smalldatetime字段中作为mindatetime + timespan。

I was thinking to store it in a smalldatetime field as mindatetime + timespan. Or maybe as an int representing an offset to some minimum date.

任何人都有这方面的经验?

Anyone has any experience with this?

推荐答案

如果开始时间很重要(因为你记录了一个事件),那么你总是想把它存储为一个datetime,所以你可以读回它以后,存储后续的持续时间可以简单地是另一个已结束的日期时间。

If the start time is significant (because your recording an event for example) then you will always want to store it as a datetime so you can read it back later, storing the subsequent duration can simply be another "ended" datetime.

如果它的任意持续时间(电影长度等),我只是将它存储为整数的秒,图层显示为小时/天等。

If its an arbitrary duration (movie length etc) I would simply store it as seconds in an integer, then add prettifying code in the presentation layer to display it as hours/days etc.

这篇关于在sql server中存储持续时间(timespans)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆