Need a function to convert duration to any meaningful time measurement

  • In msdb.dbo.sysjobhistory they have duration not in seconds or minutes, but in a format like 'ddhhmmss'. Does somebody have a function that converts it to seconds or minutes ?

    Thanks

  • First, is it stored as text or a number?

  • It's a number. For example 101 means 1 min 1 sec.

  • I'm sure there's a better way ... but here's one solution:

    CREATE FUNCTION fn_GetSeconds(@hhmmss int)

    RETURNS int

    As

    Begin

    DECLARE @j-2 varchar(6)

    SET @j-2 = right('000000' + cast(@hhmmss as varchar(6)), 6)

    RETURN substring(@j, 1, 2) * 24 * 60 + substring(@j, 3, 2) * 60 + substring(@j, 5, 2)

    End

    Go

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

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