• Elegant solution (I too like the trick to get the correct day regardless of datefirst!  Clever!).  BUT...  recursion in SQL is limited to 32 calls (XMAS holidays in schools, for example, go a lot longer than this) - it could easily have been done with a simple loop, or better yet, a simple select statement...

    In our software where we have to keep track of days a clinic is open for business, rather than messing around with such procedures, we just have a dates table with one value for each day and a bit flag representing opened or closed...  Makes reporting VERY easy and you can join to the table easily to group days together efficiently, etc.  For similar ideas and more info on why just storing the data in a table can be efficient, look up "numbers table" on this site - Adam Machanic has quite a bit written about them.

    But I still like that modulus trick!!