Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Time DataType into AM PM Format:

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?

like image 985
thevan Avatar asked May 31 '12 06:05

thevan


People also ask

How do I show time in AM PM in SQL?

Get time format of datetime in sql. ORDER BY expr1 ; SUBSTRING(CONVERT(varchar(20), yourdate, 22), 18, 3)-->it gives you a am/pm.

How do I get 24 hour time in SQL?

In SQL Server 2012, we can use Format function to have suitable date time format. Use capital letter 'HH:mm:ss' for 24 hour date time format.


1 Answers

In SQL 2012 you can use the Format() function.

https://technet.microsoft.com/en-us/library/hh213505%28v=sql.110%29.aspx

Skip casting if the column type is (datetime).

Example:

SELECT FORMAT(StartTime,'hh:mm tt') AS StartTime FROM TableA 
like image 200
Dennis Avatar answered Nov 13 '22 00:11

Dennis