Convert Time DataType into AM PM Format:

select, sql-server, sql-server-2008, time

Solution

Use following syntax to convert a time to AM PM format.

Replace the field name with the value in following query.

select CONVERT(varchar(15),CAST('17:30:00.0000000' AS TIME),100)

Output: 5:30PM

Better option is available with Sql 2012. First parameter should be of datetime data type.

DECLARE @d DATETIME = '10/01/2011 13:14';
SELECT FORMAT(@d,'hh:mm tt') 

Output : 01:14 PM

Problem

I have one Table which has two fields such as "StartTime" and "EndTime". The DataType of the Two columns are Time. So the Values of the Table looks like as follows: ``` TableA: StartTime EndTime ------------------ ---------------- 17:30:00.0000000 17:57:00.0000000 ``` But I need the result as ``` StartTime EndTime ------------------ ---------------- 05:30 PM 05:57 PM ``` When I select the table. How to get time in AM PM Format?

Original source