FORMAT function not working in sql server 2008 R2

sql, sql-server, sql-server-2008

Solution

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.

Problem

``` 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 an error: 'FORMAT' is not a recognized built-in function name. How can I use `FORMAT` function?

Original source