You can use a combination of CONVERT, RIGHT and TRIM to get the desired result:
SELECT ltrim(right(convert(varchar(25), getdate(), 100), 7))
The 100 you see in the function specifies the date format mon dd yyyy hh:miAM (or PM), and from there we just grab the right characters.
You can see more about converting datetimes here.
Answer from LittleBobbyTables - Au Revoir on Stack OverflowYou can use a combination of CONVERT, RIGHT and TRIM to get the desired result:
SELECT ltrim(right(convert(varchar(25), getdate(), 100), 7))
The 100 you see in the function specifies the date format mon dd yyyy hh:miAM (or PM), and from there we just grab the right characters.
You can see more about converting datetimes here.
You can use the CONVERT function like this:
SELECT CONVERT(varchar, your_datetime, 108)
However, this is 24-hour clock, no AM/PM.
Videos
The value of time or datetime data type is not stored with format in sql server. If you want to see the time in a different format you can manipulate the way that time and datetime data types are displayed when converted to a varchar (or nvarchar,nchar,char) data type using some built in functions.
Most often with convert() styles
select convert(char(5),convert(time(0),sysdatetime()))
returns: 22:01
In sql server 2012+ you can use format()
select format(sysutcdatetime(),'HH:mm')
returns: 22:01
But format() can be slower, take a look here: format() is nice and all, but… - Aaron Bertand
SELECT LEFT(CAST(getdate() AS Time),5) AS Hours