I have a table with hour values. I need to convert the hour value into AM/PM 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 val to be converted into varchar. Is there any other way or inbuilt function available in SQL Server to do this?
SELECT FORMAT(DATEADD(hh,val,'00:00:00'),'hh:mm tt')
FROM YourTable
Try the following:
SELECT TIMEFROMPARTS(val,0,0,0,0)
FROM [table];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With