Home > Mobile >  @@DATEFIRST not returning results as described in the docs
@@DATEFIRST not returning results as described in the docs

Time:04-06

I have read this enter image description here

CodePudding user response:

I think you may be misunderstanding the docs. The docs for DATEFIRST say, as you've seen:

Sets the first day of the week

So, the value of DATEFIRST determines which day gets numbered 1, the first day of the week. With DATEFIRST set to 7, as the table goes on to show, Sunday will be considered the first day of the week - day number 1.

With that setting, DATEPART for weekday will return 1 for any Sunday, because Sunday is considered the first day of the week.


It is perhaps unfortunate that numbers are used as the argument to SET DATEFIRST, since naturally this confusion arises. It might have been nice if we could say SET DATEFIRST Sunday to make it obvious what we mean, but unfortunately that's not the syntax.

  • Related