Sabi Tech
Sabi Tech

Reputation: 81

How to convert format to12 HRS instead of 24hrs SQL

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

Upvotes: 0

Views: 50

Answers (2)

Pirate X
Pirate X

Reputation: 3093

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

Upvotes: 1

John Cappelletti
John Cappelletti

Reputation: 81960

If SQL Server 2012+

Select Format(GetDate(),'hh:mm:ss tt')

Returns

03:55:30 PM

Upvotes: 1

Related Questions