KnowDotNet NetRefactor

Convert Number of Seconds to 00:00:00 Format

by William Ryan
Print this Article Discuss in Forums

There may be a time in your career where you are given a number of seconds and need to convert it to Hour:Minute:Second format.  This is a pretty common task, and writing a client side solution for it is pretty simple.  On the other hand, it's unnecessary thanks to some of SQL Server's intrinsic functions and date formatters:

So, let's say that you had a field called Total_Seconds and you needed to format is as mentioned above.   Basically, this little code snippet can do it for you:

CONVERT(VARCHAR,DATEADD(s,Total_Seconds,'19000101'),8) AS 'Some Alias'


That's all there is to it!

Writing Add-Ins for Visual Studio .NET
Writing Add-ins for Visual Studio .NET
by Les Smith
Apress Publishing