RSS Feed

FORMAT()

FORMAT()

FORMAT(): FORMAT in SQL SERVER 2012 is a string function which can be used for returning the input parameter in a specified format with optional culture (if given as parameter) . Developer can use this FORMAT method for localized formatting of date & time and numeric values as strings. In place of FORMAT, one can use CAST or CONVERT for general data type conversions.

Syntax of FORMAT():

FORMAT (value, format [, culture ] )

Example of FORMAT():

Formatting with numbers

DECLARE @input INTEGER = 102432846;
SELECT FORMAT(@input,'###-##-####') AS 'Formatted Number';

Output comes out to be: 102-43-2846

Formatting with DateTime

SELECT FORMAT( GETDATE(), 'dd/mm/yyyy', 'en-US' ) AS 'Formatted DateTime';

Output will be printed as: 06/12/2012

For complete post go to SQL Server 2012 Enhancements.