IT Questions and Answers :)

Thursday, March 5, 2020

In SQL, the function select datepart(dw,getdate()) returns a number representing the current day of the week. You want to use 1 for Monday, 2 for Tuesday, up to 7 for Sunday. How do you set this?

In SQL, the function select datepart(dw,getdate()) returns a number representing the current day of the week. You want to use 1 for Monday, 2 for Tuesday, up to 7 for Sunday. How do you set this?

  • set datefirst 0;
  • set datefirst 2;
  • set datefirst 7;
  • set datefirst 1; 


EXPLANATION

Datefirst says which day of the week will be treated as the start of the week and return the value 1,
When setting Datefirst, 1 means Monday will be the start of the week. The default (7) means Sunday will be the start of the week. Zero is not a valid option and does not change the current setting.
For more details, see: https://docs.microsoft.com/en-us/sql/t-sql/statements/set-datefirst-transact-sql?view=sql-server-2017

SOURCE

https://docs.microsoft.com/en-us/sql/t-sql/statements/set-datefirst-transact-sql?view=sql-server-2017
Share:

0 comments:

Post a Comment

Popular Posts