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?
SQL Server FORMAT() Function The FORMAT() function formats a value with the specified format (and an optional culture in SQL Server 2017). Use the FORMAT() function to format date/time values and number values. For general data type conversions, use CAST() or CONVERT().
In a SQL document, right-click the SQL script, click Active Format Profile, and select the required format. 2. To apply the selected format profile, select the SQL document or the fragment of the code and press Ctrl+K, then Ctrl+F. In addition, you can create a custom format profile based on the available profiles.
MySQL FORMAT() FunctionThe FORMAT() function formats a number to a format like "#,###,###. ##", rounded to a specified number of decimal places, then it returns the result as a string.
FORMAT returns NULL for errors other than a culture that is not valid. For example, NULL is returned if the value specified in format is not valid. The FORMAT function is nondeterministic.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With