Format does work on time(7), but you have to escape the colon and hh mm are lower case.
Declare @HourMonday as time(7) = '13:45:00'
Select FORMAT(@HourMonday, N'hh\:mm')
Answer from AzzP on Stack OverflowFormat does work on time(7), but you have to escape the colon and hh mm are lower case.
Declare @HourMonday as time(7) = '13:45:00'
Select FORMAT(@HourMonday, N'hh\:mm')
You should always format your data in the presentation layer. If there are circumstance where the TIME datatype cannot be formatted by your UI, you can cast the value to a DATETIME which will more than likely be supported.
SELECT CAST(TimeColumn AS DATETIME)
FROM MyTable
No, you cannot do anything about the format SQL Server uses to store the Time datatype. You can only use tricks like the one you mentioned at query-time to deliver the output in a desired format. Or better yet, do the formatting in the front-end application.
you can try to use DATEPART(HH... with case statements or IF/ELSE to alter the times past noon, and CONCAT am or pm on the end
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