March 3, 2010 at 2:39 pm
Hi Friends
here is the situation i am facing.I have dispatch time column like this.
1200
1345
1245
So i want to convert into lik ethis
12:00
13:45
12:45
Any ideas please?
Thanks.
March 3, 2010 at 2:54 pm
One way would be something like :
declare @Time int
select @Time = 0630
select
SUBSTRING(CAST(@Time + 10000 AS varchar),2,2) + ':' + SUBSTRING(CAST(@Time + 10000 AS varchar),4,2)
March 3, 2010 at 2:56 pm
It depends on several things:
What is the format the original values are stored as?
How do you want to display times before 10:00 (w/ or w/o leading zero)?
Why is'n it stored as TIME format already?
And the main question: Why do you want to do it within SQL Server instead of doing the formatting with the app/frontend?
DECLARE @i INT
SET @i = 900
SELECT RIGHT(1000+@i/100 ,2) +':' +RIGHT(@i,2)
DECLARE @C VARCHAR(4)
SET @C = '900'
SELECT LEFT(@c1,LEN(@c1)-2)+':' +RIGHT(@c1,2)
March 3, 2010 at 3:07 pm
Lutz,
Very creative. Good work!
March 3, 2010 at 4:07 pm
If your time is stored as character data, try this:
declare @i varchar(4)
set @i = '1'
select stuff(right('0000'+@i,4),3,0,':')
if it's stored as numeric data, try this:
declare @i int
set @i = 1
select stuff(right('0000'+convert(varchar(4),@i),4),3,0,':')
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
March 3, 2010 at 4:10 pm
Thanks friends,
It worked excellent..............
Once again thanks for your help...
March 3, 2010 at 5:16 pm
anitha.cherukuri (3/3/2010)
Thanks friends,It worked excellent..............
Once again thanks for your help...
There are 3 different examples above... which one did you end up using?
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply