1
kudos
spam Kudos Remove

Time is no use for recording Time

published 734 days, 13 hours, 8 minutes ago posted by sasa 744 days, 33 minutes ago
Wednesday, February 03, 2010 12:05:18 AM GMT Sunday, January 24, 2010 12:40:20 PM GMT

 

I was asked by a client about the new Time datatype in SQL 2008. They wanted to store the duration of some work so they could use the nice date time functions to get the hours, minutes, seconds etc.

However you can't use the Time date type for that, because it can only hold time up to midnight after that it roles around to 0. Not much use if something takes longer than 24 hrs to run.

If you would like to have such a feature then vote for the reccomendation for an interval data type. https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=432281

If you can't wait until fro a nother 3 or 4 years then you could cheat.

If you use the datetime data type then you can add these together and get the behaviour you want. So you can get 04:53 and add it to 20:52.

To find the hours, months etc you perform a datedfif with 0. like this

@time datetime

@time = cast('4:53' as datetime ) + cast('20:52'

category: News | clicked: 0 | | source: sqlblogcasts.com | show counter code
tags: SQL Server 2008, Suggestions, Tips and Tricks

No comments yet, be the first one to post comment.

To post your comment please login or signup