One of the most frequently
asked questions in SQL Server forums is how to format a datetime value or
column into a specific date format. Do you think January 5th 2013 should be shown as 1/5/2013 or
5/1/2013? The best answer is to each their own. The FORMAT function lets
you pick the style, or better yet it can be relevant to the culture of the computer
running the query.
It is worth to note that the
outputs of these date formats are of VARCHAR data types already and not of DATETIME data type. With this in mind,
any date comparisons performed after the datetime value has been formatted are
using the VARCHAR value of the date and time and not its original DATETIME value.
The FORMAT( ) function is used to format how a field is
to be displayed.
SQL
FORMAT( ) Syntax:
SELECT
FORMAT(column_name,format) FROM table_name;