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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 t-sql question

Author  Topic 

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2009-07-09 : 14:18:07
I want to convert the following time values into HH:MIAM or HH:MIPM,
I have the following data in my table:

Create table #temp
(time char(4))

Insert into #temp
select '0900'
union
select '0915'
union
select '0930'
union
select '1200'
union
select '1300'
union
select '1515'
union
select '1530'
union
select '1545'
union
select '1600'

select * from #temp

I want for example the following output:
9AM for '0900'
3:45PM for '1545'


Thanks!

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-09 : 14:36:34
Best Hack I could come up with


SELECT RIGHT(
CONVERT(varchar(50),
CONVERT(datetime,
'1900-01-01 '+LEFT([time],2)+':'+RIGHT([time],2))
,0),7)
FROM #temp





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -