Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Convert seconds to a timestring

By Wilfred van Dijk,

If you use datediff to determine how log something is running, you'll have to make the choice how to represent it. If you choose minutes, SQL will round the datediff time. If you choose seconds, you'll have to determine how many minutes + some seconds this was (try 302 seconds)

Since I'm lazy, I wrote this function which converts a number of seconds to a 'human' time format. for example 302 seconds is represented as '00:05:02', meaning 5 minutes and 2 seconds.

Note: If this function is behaving strange, copy/paste the code into an editor and replace "goofy" characters

NOTE: Thanks to Nigel, this function is replaced by a fantastic use of CONVERT/DATEADD)

 

 

Total article views: 1347 | Views in the last 30 days: 1
 
Related Articles
FORUM

Convert DateDiff into Hours, Minutes, Seconds, Milliseconds

I have the hours, minutes, and seconds...but need the milliseconds.

BLOG

SQLBIGeek’s Function Friday – Convert Job Duration to Seconds

Brian K. McDonald SQLBIGeek Twitter: @briankmcdonald Welcome to the second post of my “...

FORUM

OPENROWSET select statement performance -- runs in 4 seconds on test server vs. 3 minutes on production server.

OPENROWSET select statement performance -- runs in 4 seconds on test server vs. 3 minutes on product...

FORUM

Julian Date Conversion Function Issue

Conversion Function not returning Seconds on date

FORUM

Time - Adding minutes and seconds

I have the 2 columns with time datatypes. select top 5 [Connect Time2],[totalTime2] from dbo.veri...

Tags
convert    
date    
time    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones