Adding Days to a Date but Excluding Weekends

前端 未结 11 2186
萌比男神i
萌比男神i 2020-12-01 15:47

Given a date how can I add a number of days to it, but exclude weekends. For example, given 11/12/2008 (Wednesday) and adding five will result in 11/19/2008 (Wednesday) rath

11条回答
  •  被撕碎了的回忆
    2020-12-01 16:35

    Given the number of the original day in the year D and original day in the week W and the number of workdays to add N, the next weekday number is

    W + N % 5.
    

    The next day in the year (with no wraparound check) is

    D + ((N / 5) * 7) + N % 5).
    

    This is assuming that you have integer division.

提交回复
热议问题