storing durations (timespans) in sql server

前端 未结 3 1149
轮回少年
轮回少年 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 02:04

    What I would do is have 2 columns one being the last time an event was fired and the other being how long between fires of the event. That way you could do a query of the dateDiff between the last time fired and now() and see if that value is greater then the duration between fires.

    As for the value of the duration I would have it be the minimum value of time that you need. Such that if you have a min value of 5 minutes then the column should be in minutes. if you have a min value in seconds then it should be in seconds.

提交回复
热议问题