RAKESH HOLKAR RAKESH HOLKAR - 3 months ago 33
SQL Question

FORMAT function not working in sql server 2008 R2

DECLARE @d DATETIME = '01/01/2011';
SELECT FORMAT ( @d, 'd', 'en-US' ) AS US_Result;


I am using above code in SQL Server 2008 R2 but it is encountering error 'FORMAT' is not a recognized built-in function name.
How can i use FORMAT funciton???

Answer

FORMAT function is available from version 2012 onwards. In earlier versions, use this:

DECLARE @d DATETIME = '01/01/2011'; 
SELECT replace(replace(' '+convert(varchar(10),@d,101),' 0',''),'/0','/')

However, formatting is the job of the front end application.