AbleTech AbleTech - 5 months ago 7
SQL Question

How to convert format to12 HRS instead of 24hrs SQL

SELECT
Warehouses.Name, CONVERT(TIME,AirwayBillTrucks.CheckOutTime) AS CheckOutTime,

Answer

Assuming you are using SQL Server - This will fetch you 12hr format

SELECT CONVERT(VARCHAR, Your_column_Name, 100) AS 12_hr_format

To show just the time

SELECT RIGHT(CONVERT(VARCHAR, Your_column_Name, 100), 7) AS time_in_12hr_format

OR simply use the code 108

SELECT CONVERT(VARCHAR, Your_column_Name, 108) AS time_in_12hr_format

Conversion -
100 - mon dd yyyy hh:miAM (or PM)
121 - yyyy-mm-dd hh:mi:ss.mmm(24h)

You can see all the type of format conversion here at Microsoft CAST and CONVERT