• ringovski - Saturday, May 5, 2018 3:34 AM

    Thanks a lot for the script. Can you explain the logic behind it so i can understand it?

    The logic for the weekdays is that date 0 is a Monday, modulus 7 of the number of dates from date 0 will return 5 for Saturdays and 6 for Sundays, hence limit the results to the set where that number is lower than 5 will return working (non weekend) days.
    The conversion of getdate to a date removes the time part which simplifies the temporal framing of the query and adding 29 days allows us to use less than rather than less or equal to, slightly better performance.
    😎