join the MSSQLTips community

MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

 
An easier way to make MSDB integer time readable - MSSQLTips

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

An easier way to make MSDB integer time readable

Last post 06-13-2009 4:41 PM by admin. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-20-2009 5:59 AM

    An easier way to make MSDB integer time readable

    A tip was posted that shows a way to convert SQL Server's integer time value into a readable format, and does so by examining the number of digits in the integer to determine zero padding.  This method works well, but does not convert time values from 00:00:01 up to 00:09:59.  The related tip is posted here:

    http://www.mssqltips.com/tip.asp?tip=1744

    Here is an easier way to convert the integer value to a readable string with support for all time values:

    SET @time_out = right('000000' + convert(varchar, @time_in), 6)

    SET @time_out = LEFT(@time_out,2) + ':' + SUBSTRING(@time_out, 3,2) + ':' + RIGHT(@time_out, 2)

    Here, the @time_out variable is a varchar(8), and @time_in is the integer time value to convert.

     This method is clean and simple and covers all possible time values from midnight to midnight.

     

  • 06-13-2009 4:41 PM In reply to

    Re: An easier way to make MSDB integer time readable

    Thanks for posting another solution.

Page 1 of 1 (2 items)