What is the difference between DATEFIRST and @@DATEFIRST in SQL Server


DATEFIRST keyword uses to reset the first day of the week in SQL Server and @@DATEFIRST returns the current value for the session of DATEFIRST.

For Example:-
As we know SQL Server set default language US English and SQL Server sets by default DATEFIRST to 7 (Sunday).

SET DATEFIRST 6
If we execute the above query it will set Saturday as the first day of the week.
@@DATEFIRST, will return the current value of SET DATEFIRST for the session.

SET LANGUAGE french
GO
SELECT @@DATEFIRST
GO
-- the result will return 1 (Monday)

SET LANGUAGE us_english
GO
SELECT @@DATEFIRST
GO
-- the result will return 7 (Sunday)

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...