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