Format a date value into a specified string representation.
DECLARE @d DATETIME = ’12/01/2018′; SELECT FORMAT (@d, ‘d’, ‘en-US’) AS ‘US English Result’, FORMAT (@d, ‘d’, ‘no’) AS ‘Norwegian Result’, FORMAT (@d, ‘d’, ‘zu’) AS ‘Zulu Result’; |
The FORMAT() function in SQL Server 2017 and later formats a value according to a specified format string (and optionally, a culture).
Use FORMAT() for formatting date/time and number values. For other data type conversions, consider using CAST() or CONVERT().
FORMAT(value, format, culture) |
Parameter |
Description |
value |
Mandatory. Specifies the value that will undergo formatting. |
format |
Mandatory. Specifies the format pattern used for formatting the value. |
culture |
Optional. Specifies a culture for formatting purposes, available from SQL Server 2017 onward. |
Works in: |
SQL Server (from 2012 onward) and Azure SQL Database |
Format a numerical value into a desired string representation.
SELECT FORMAT(123456789, ‘##-##-#####’); |