Seconds To Time

  • Hi people i have the following line

    @example = Cast(SUM(DateDiff(second,vi.dtstart,vi.DtEnd)) AS float)

    the things is if i do somethink like this

    Convert(char(8), @example, 114)

    it converts to time, very nice, perfect but when the time goes over 24h it returns only the excedent of 24h so 30h would show 6h

    is there any workaround ?

    thanks in advance

  • Add % (3600 * 24). That will wipe out anything above 24 hours. This must be applied when the data is in seconds.

  • This is a presentation layer task, not a database task. What you should do is output the seconds to the presentation layer and format it there.

    That being said, try this: -

    DECLARE @seconds INT

    SET @seconds = 90000

    SELECT CONVERT(VARCHAR(6), @seconds/3600) + ':' + RIGHT('0' + CONVERT(VARCHAR(2), (@seconds % 3600) / 60), 2)

    + ':' + RIGHT('0' + CONVERT(VARCHAR(2), @seconds % 60), 2)

    --Edit--

    Out of curiosity Remi, how many arms do you have? I figure you must have at least 8 to keep up with your workload 😛


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • It's called touch-typing.

    You might try it someday :hehe:.

    P.S. Totally agree that this should be done at the presentation layer. Just getting tired of saying that ;-).

  • skcadavre (8/11/2011)


    This is a presentation layer task, not a database task. What you should do is output the seconds to the presentation layer and format it there.

    It is said then !

    thought there could be a 'clean' way to this

    Thanks for the support

  • Ninja's_RGR'us (8/11/2011)


    It's called touch-typing.

    You might try it someday :hehe:.

    P.S. Totally agree that this should be done at the presentation layer. Just getting tired of saying that ;-).

    lol, touch typing? Does that have intellisense? 😛


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • ariel_mlk (8/11/2011)


    skcadavre (8/11/2011)


    This is a presentation layer task, not a database task. What you should do is output the seconds to the presentation layer and format it there.

    It is said then !

    thought there could be a 'clean' way to this

    Thanks for the support

    Generally, it's better to do formatting in the presentation layer. It can be done in T-SQL, as Remi and I suggested.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • ariel_mlk (8/11/2011)


    skcadavre (8/11/2011)


    This is a presentation layer task, not a database task. What you should do is output the seconds to the presentation layer and format it there.

    It is said then !

    thought there could be a 'clean' way to this

    Thanks for the support

    Yes format function in .net if very effective at this. Makes it extremelly clean to t-sql. 😀

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply