[start_date] + interval ([day_increment] div 6) * 7 +
MID('012345012346012356012456013456023456012345', 6 * WEEKDAY([start_date]) +
mod([day_increment],6) + 1, 1) + if(mod([day_increment], 6) = 0, -1, 0) day
Stumbled upon the above which calculates your end_date taking into account non working days (Sunday). This is for a 6 day work week, where Sunday is a non-working day. I know what each part does, however I'm having trouble understanding WHY it was done.
Specific parts I am confused about are:
[day_increment] div 6) * 7
Is my understanding correct that this calculates how many weeks are in[day_increment]
, converted to days via multiplying 7? E.g. increment by 16 days, there are 2 weeks worth of business days (16 div 6),* 7, there are 14 days baseline. I'm not exactly sure why 6 and 7 were chosen.'012345012346012356012456013456023456012345'
how was the matrix of this concatenated string generated? Logic doesn't seem to follow that explained here: link6 * WEEKDAY([start_date]) + mod([day_increment],6) + 1, 1)
why are we multiplying by 6? What is 6? My guess is that we convert this to a multiple of 6 because there are 6 working days? Furthermore, why are we taking the modulo of increment divided by 6? What is the modulo for, and is 6 the number of business days?
Bulletpoint 2 Update:
I think I've figured out how the string was generated. It's a matrix made up of days of week on the row labels, then n + x as column labels, where x is the number of business days. Values are the calendar days to increment by.