Number to date conversion (hour:Minutes:Sec)

  • Hi

    I have a Column say (Tab1.Col_A number (20,5)) store seconds.

    I want result in Hours:Minutes:Seconds format

    Please advise how to get above outcome.

    Note:- At the moment I do Col_A/60 for minutes and Col_A/(60X60) for hours but it is not accurate it some time give 12Hours & 80Minutes.

    Wishes

    Jawad

     

  • You need to use function to get field in hh:mm format

    function D_Time (@S_Time as int)

    as

    begin

    DECLARE @STR INT

    DECLARE @QRY VARCHAR(10)

    SET @STR=@S_Time

    SET @QRY=CAST(@STR/3600 AS VARCHAR(2))+':'

    SET @STR=@STR%3600

    SET @QRY=@QRY+CAST(@STR/60 AS VARCHAR(2))+':'+CAST(@STR%60 AS VARCHAR(2))

    return @QRY

    end

  • This works for periods less than 1 day.

    declare @secs float

    set @secs = 15000

    select convert(char(8), cast(@secs / 86400 as datetime), 8)

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • thanks

    Jawad

     

Viewing 4 posts - 1 through 3 (of 3 total)

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