Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Conversion of int to time format

Author  Topic 

arch88
Starting Member

1 Post

Posted - 2011-09-26 : 03:21:59
Hi,

In my table the time is stored as int. For eg, 223007. I need to convert it to 10:30:07 PM. What is the simplest way in which i can achieve this?
Please help!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-26 : 04:12:45
[code]
DECLARE @in int
SET @in =223007
SELECT RIGHT(CONVERT(varchar(30),DATEADD(ss,@in%10,DATEADD(mi,((@in%10000)/100),DATEADD(hh,@in/10000,0))),109),15)

[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-09-26 : 11:04:45
Always use datetime datatype and do formation at front end application.


DECLARE @in int
SET @in =223007
select right(convert(varchar(30),convert(datetime,STUFF(stuff(@in,5,0,':'),3,0,':')),9),15)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -