FORMAT (Transact-SQL)
Returns a value formatted with the specified format and optional culture.
Use the FORMAT function for locale-aware formatting of date/time and number values as strings. For general type conversions, continue to use CAST or CONVERT.
In the case of errors other than a culture that is not valid, such as a format that is not valid, FORMAT returns a null.
FORMAT relies on the presence of .the .NET Framework Common Language Runtime (CLR).
This function will not be remoted since it depends on the presence of the CLR. Remoting a function that requires the CLR would cause an error on the remote server.
More information about the value parameter
Acceptable data types for the value argument are listed in the following table, together with their .NET Framework mapping information:
|
Category |
Type |
.NET type |
|---|---|---|
|
Numeric |
bigint |
Int64 |
|
Numeric |
int |
Int32 |
|
Numeric |
smallint |
Int16 |
|
Numeric |
tinyint |
Byte |
|
Numeric |
decimal |
SqlDecimal |
|
Numeric |
numeric |
SqlDecimal |
|
Numeric |
float |
Double |
|
Numeric |
real |
Single |
|
Numeric |
smallmoney |
Decimal |
|
Numeric |
money |
Decimal |
|
Date and Time |
date |
DateTime |
|
Date and Time |
time |
TimeSpan |
|
Date and Time |
datetime |
DateTime |
|
Date and Time |
smalldatetime |
DateTime |
|
Date and Time |
datetime2 |
DateTime |
|
Date and Time |
datetimeoffset |
DateTimeOffset |