Date/Time Functions – @@DATEFIRST

I am on the home stretch with my writing of short articles or tidbits on Transaction SQL date/time functions.

We already talked about functions like DATEPART() that returns the day of the week as an integer and DATENAME() that returns the day of the week as text.

But what is the first day of the week? The default for the US English language is 7, or Sunday. However, this setting differs between countries.

Today, I will be talking about @@DATEFIRST, a configuration function which returns the current session value and SET DATEFIRST, a set statement which changes the value for the current session (SPID).

The examples below are sample calls to these functions. Their impact if felt when a developer uses the DATEPART() and DATENAME() functions.

The output from the test is listed below.

To recap this article, the @@DATEFIRST configuration function tells you what day is the first one of a given week. This value is controlled at the session level. The SET DATEFIRST statement can be used to override this value.

Related posts

Leave a Comment