bmsqldev bmsqldev - 1 year ago 53
SQL Question

Convert Integer value into Hour value (AM / PM) in SQL Server

I have a

with hour
. I need to convert the hour value into
format, as shown here:

val hour
9 9:00 AM
19 7:00 PM
10 10:00 AM
19 7:00 PM
14 2:00 PM

I have tried this logic:

declare @timing varchar(5)='15:02'

declare @time time=cast(@timing as time)
select convert(varchar(50),@time, 100)

But this requires
to be converted into
. Is there any other way or inbuilt function available in SQL Server to do this?

mcr mcr
Answer Source
SELECT FORMAT(DATEADD(hh,val,'00:00:00'),'hh:mm tt') 
FROM YourTable