SQL: Calculating Day of the Week Reliably in T-SQL
Some T-SQL functions like DATEPART work differently based upon your session settings. If you want to write reliable code, you should always check for these issues, and try to write code that’s impervious to these settings.
Let’s take finding the day of the week as an example. It might seem that to find out if a day is a Sunday, you could just do this:
DECLARE @DayToCheck date = ‘20190224’;
2019-02-15
