Change the Date Format For the Current Session in SQL Server

Whenever you connect to SQL Server, a bunch of default settings are applied to your session. These include the language and the date format settings.

The date format is normally determined by your default language. For example, if your default language is us_english, then the default date format will probably be mdy, and the first day of the week will be day 7 (Sunday).

If you change your language, you the date format will implicitly be updated accordingly.

However, you still have the option of changing the date format without changing the language. To do this, you can use SET DATEFORMAT.

Example

First, let’s take a look at the current settings.

DBCC USEROPTIONS;

Result:

+-------------------------+----------------+
 | Set Option              | Value          |
 |-------------------------+----------------|
 | textsize                | -1             |
 | language                | us_english     |
 | dateformat              | mdy            |
 | datefirst               | 7              |
 | lock_timeout            | 5000           |
 | quoted_identifier       | SET            |
 | arithabort              | SET            |
 | ansi_null_dflt_on       | SET            |
 | ansi_warnings           | SET            |
 | ansi_padding            | SET            |
 | ansi_nulls              | SET            |
 | concat_null_yields_null | SET            |
 | isolation level         | read committed |
 +-------------------------+----------------+ 

So my current language is us_english and the date format is mdy.

Let’s change the date format and check again.

SET DATEFORMAT dmy;
DBCC USEROPTIONS;

Result:

+-------------------------+----------------+
 | Set Option              | Value          |
 |-------------------------+----------------|
 | textsize                | -1             |
 | language                | us_english     |
 | dateformat              | dmy            |
 | datefirst               | 7              |
 | lock_timeout            | 5000           |
 | quoted_identifier       | SET            |
 | arithabort              | SET            |
 | ansi_null_dflt_on       | SET            |
 | ansi_warnings           | SET            |
 | ansi_padding            | SET            |
 | ansi_nulls              | SET            |
 | concat_null_yields_null | SET            |
 | isolation level         | read committed |
 +-------------------------+----------------+ 

So I successfully changed the date format without changing the language. However, datefirst remains the same. If you want to change the datefirst value, use SET DATEFIRST.

SET DATEFIRST 1;
DBCC USEROPTIONS;

Result:

 
+-------------------------+----------------+
 | Set Option              | Value          |
 |-------------------------+----------------|
 | textsize                | -1             |
 | language                | us_english     |
 | dateformat              | dmy            |
 | datefirst               | 1              |
 | lock_timeout            | 5000           |
 | quoted_identifier       | SET            |
 | arithabort              | SET            |
 | ansi_null_dflt_on       | SET            |
 | ansi_warnings           | SET            |
 | ansi_padding            | SET            |
 | ansi_nulls              | SET            |
 | concat_null_yields_null | SET            |
 | isolation level         | read committed |
 +-------------------------+----------------+ 

In this case I’ve changed the first day of the week to be day 1, which is Monday.

Reset it Back

Setting the language will implicitly set the dateformat and datefirst settings back to their default values for that language (even if you reset the language to the current language).

So in my case, I can reset the language to us_english, and it will also reset the date format values.

SET LANGUAGE us_English;
DBCC USEROPTIONS;

Result:

+-------------------------+----------------+
 | Set Option              | Value          |
 |-------------------------+----------------|
 | textsize                | -1             |
 | language                | us_english     |
 | dateformat              | mdy            |
 | datefirst               | 7              |
 | lock_timeout            | 5000           |
 | quoted_identifier       | SET            |
 | arithabort              | SET            |
 | ansi_null_dflt_on       | SET            |
 | ansi_warnings           | SET            |
 | ansi_padding            | SET            |
 | ansi_nulls              | SET            |
 | concat_null_yields_null | SET            |
 | isolation level         | read committed |
 +-------------------------+----------------+