storing durations (timespans) in sql server

前端 未结 3 1152
轮回少年
轮回少年 2021-02-07 01:05

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

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

3条回答
  •  故里飘歌
    2021-02-07 01:51

    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.

提交回复
热议问题