Hello, I study t-sql. I got to the section where the formatted date output is used. On one of the official Microsoft sites, the link describes how to use the FORMAT() function.

Wrote this query:

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

But when executing this script, an error occurs:

"Message 195, level 15, state 10, line 2 FORMAT is not the name of the built-in function."

Tell me what could be the matter? I use MS SQL 2008R2, Windows7.

  • In the link given by you it is written that the necessary function is available starting from version mssql 2012 - Bald
  • Thank you Bald, he is to blame. And are there similar functions in earlier versions? - student007

1 answer 1

as the user wrote Bald, the FORMAT () function is available starting with SQL SERVER 2012 .

Earlier you can use this:

 DECLARE @d DATETIME = '10/01/2011'; SELECT CONVERT(VARCHAR(12) , @d , 3) 

Result:

 01/10/11 

For reference

  • Thanks, I will use)) - student007