AbleTech AbleTech - 6 months ago 10
SQL Question

How to convert format to12 HRS instead of 24hrs SQL

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


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