Showing posts with label Seconds. Show all posts
Showing posts with label Seconds. Show all posts

Efficient way to Convert Seconds in to hours,minutes and Seconds in Sql Server

Suppose you have a column contains time in seconds, and need to convert those seconds into time format (hh:MM:ss), following is the best method for doing this.


SELECT CONVERT(CHAR(8),DATEADD(SECOND,,0),108);


Ex: Suppose, you want to convert 105 seconds in to time format, then


SELECT CONVERT(CHAR(8),DATEADD(SECOND,105,0),108);


will returns

00:01:45

If you want only minutes and seconds, then you can get it with the below query


SELECT RIGHT(CONVERT(CHAR(8),DATEADD(SECOND,105,0),108),5);


will returns

01:45

It is the  fastest solution of all the other solutions.