SQL Server….
I am trying to select the week number from a date. Our company counts the first Monday of the year as week 1 with any days before that as week 0.
So example for 2022 with expected result….
1/1/2022 - Sat - Week 0
1/2/2022 - Sun - Week 0
1/3/2022 - Mon - Week 1
etc.
1/1/2023 - Sun - Week 0
1/1/2023 - Mon - Week 1
etc.
I have tried the 'week' and 'iso_week' functions plus setting the starting day of the week with 'datefirst' declaration, as well as various datepart statements.
I'm sure this is simpler than I am making it but too much googling and overthinking at this point. Maybe a set of case statements with math to derive the correct value depending on day counts and weekdays?
Appreciate any suggestions.
I am trying to select the week number from a date. Our company counts the first Monday of the year as week 1 with any days before that as week 0.
So example for 2022 with expected result….
1/1/2022 - Sat - Week 0
1/2/2022 - Sun - Week 0
1/3/2022 - Mon - Week 1
etc.
1/1/2023 - Sun - Week 0
1/1/2023 - Mon - Week 1
etc.
I have tried the 'week' and 'iso_week' functions plus setting the starting day of the week with 'datefirst' declaration, as well as various datepart statements.
I'm sure this is simpler than I am making it but too much googling and overthinking at this point. Maybe a set of case statements with math to derive the correct value depending on day counts and weekdays?
Appreciate any suggestions.