Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

FORMAT

Example

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’;

Definition and Usage

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().

Syntax

FORMAT(value, formatculture)

Parameter Values

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.

Technical Details

Works in:

SQL Server (from 2012 onward) and Azure SQL Database

More Examples

Example

Format a numerical value into a desired string representation.

SELECT FORMAT(123456789‘##-##-#####’);