Converting Integet to Time:
-
Hi I am trying to convert an integer value to time is it possible in a query to convert? For example a value 130210 stored as int should display as hh:mm:ss format.
Shahzad Aslam Software Engineer Softech Systems Limited Cell: +92-321-4606036 Email: shehzadaslam@hotmail.com
-
Hi I am trying to convert an integer value to time is it possible in a query to convert? For example a value 130210 stored as int should display as hh:mm:ss format.
Shahzad Aslam Software Engineer Softech Systems Limited Cell: +92-321-4606036 Email: shehzadaslam@hotmail.com
I use:
CREATE FUNCTION [Lib].[IntToTime] (@Subject INT)
RETURNS DATETIME AS
BEGIN
DECLARE @result AS DATETIME
SET @result = '1970-01-01 00:00:00'SET @result = DATEADD ( HH , @Subject/10000 , @result )
SET @Subject = @Subject - @Subject/10000*10000SET @result = DATEADD ( mi , @Subject/100 , @result )
SET @Subject = @Subject - @Subject/100*100SET @result = DATEADD ( ss , @Subject , @result )
RETURN ( @result )
ENDThen you can
CONVERT
theDateTime
to string as needed. -
Hi I am trying to convert an integer value to time is it possible in a query to convert? For example a value 130210 stored as int should display as hh:mm:ss format.
Shahzad Aslam Software Engineer Softech Systems Limited Cell: +92-321-4606036 Email: shehzadaslam@hotmail.com
declare @sec int set @sec=130210 select convert(varchar(5),@sec/3600)+' Hrs : '+convert(varchar(5),@sec%3600/60)+' Min : '+convert(varchar(5),(@sec%60))+' Sec' OR --If 130210 is Second : SELECT CONVERT(varchar(8), DATEADD(second, 130210 , '0:00:00'), 108) --If 130210 is Minute : SELECT convert (varchar(8),dateadd(minute,130210 ,'0:00:00'),108) OR declare @Diff int set @Diff=130210 SELECT CONVERT(varchar(6), @Diff/3600) + ':' + RIGHT('0' + CONVERT(varchar(2), (@Diff % 3600) / 60), 2) + ':' + RIGHT('0' + CONVERT(varchar(2), @Diff % 60), 2)
Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...