Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tend to use:</p> <pre><code>CAST(FLOOR(seconds / 86400) AS VARCHAR(10))+'d ' + CONVERT(VARCHAR(5), DATEADD(SECOND, Seconds, '19000101'), 8) </code></pre> <p>The top part just gets your days as an integer, the bottom uses SQL-Server's convert to convert a date into a varchar in the format HH:mm:ss after converting seconds into a date.</p> <p>e.g.</p> <pre><code>SELECT Formatted = CAST(FLOOR(seconds / 86400) AS VARCHAR(10))+'d ' + CONVERT(VARCHAR(5), DATEADD(SECOND, Seconds, '19000101'), 8), Seconds FROM ( SELECT TOP 10 Seconds = (ROW_NUMBER() OVER (ORDER BY Object_ID) * 40000) FROM sys.all_Objects ORDER BY Object_ID ) S </code></pre> <p><strong><a href="http://sqlfiddle.com/#!3/9dbc1/2" rel="noreferrer">Example on SQL Fiddle</a></strong></p> <p><em>N.B. Change</em> <code>CONVERT(VARCHAR(5), DATEADD(..</code> <em>to</em> <code>CONVERT(VARCHAR(8), DATEADD(..</code> <em>to keep the seconds in the result</em></p> <p><strong>EDIT</strong></p> <p>If you don't want seconds and need to round to the nearest minute rather than truncate you can use:</p> <pre><code>SELECT Formatted = CAST(FLOOR(ROUND(Seconds / 60.0, 0) * 60 / 86400) AS VARCHAR(10))+'d ' + CONVERT(VARCHAR(5), DATEADD(SECOND, ROUND(Seconds / 60.0, 0) * 60, '19000101'), 8), Seconds FROM ( SELECT Seconds = 3899 ) S </code></pre> <p>I have just replaced each reference to the column <code>seconds</code> with:</p> <pre><code>ROUND(Seconds / 60.0, 0) * 60 </code></pre> <p>So before doing the conversion rounding your seconds value to the nearest minute</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload