May 28, 2020 at 1:42 pm
hi
Is there a way to SET DATEFIRST server or database wide? I need Saturday be first day of the week so in every proc I set datefirst but in views I cannot do that.
May 28, 2020 at 3:05 pm
This is based on your language setting.
SELECT top 10
*
FROM sys.syslanguages
There is a datefirst column here. If you change the language, you change this.
Apart from that, I'm not sure you can do this globally. You can likely set defaults for sessions and for connections, but that would be client by client.
Can I ask the use case?
May 30, 2020 at 4:13 am
I prefer not to depend on DATEFIRST settings in my code.
There are several pretty simple techniques to make your code independent of it.
For example, using system variable @@DATEFIRST in your code.
Or relying on the fact that zero date in SQL Server is Monday, so date number 5 is Saturday.
Therefore any day which is whole number of weeks away from day 5 is also Saturday.
Or you may use a Calendar table, which might solve more than one of your problems.
_____________
Code for TallyGenerator
May 30, 2020 at 5:29 am
This is based on your language setting.
SELECT top 10
*
FROM sys.syslanguagesThere is a datefirst column here. If you change the language, you change this.
Apart from that, I'm not sure you can do this globally. You can likely set defaults for sessions and for connections, but that would be client by client.
Can I ask the use case?
Just not for a language that starts on Saturday (or any day other than Sunday or Monday) 😉
SELECT DISTINCT (datefirst)
FROM sys.syslanguages
;
Results:
I totally agree with the methods that Sergiy stated. I also wish people would all switch to ISO standards.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply