Title: Increment TDateTime by week (working) days.
Question: How to increment a date by X number of week (working) days.
Example: Increment a Friday date by 1 will give you a Monday date.
Answer:
{For positive increments, a weekend date is treated as the previous Friday date, and for negative increments, a weekend date is treated as the following Monday date.}
function IncWeekDay(InDate: TDateTime; Increment: integer = 1): TDateTime;
begin
if Increment 0 then begin {Positive Increment}
if DayofWeek(InDate) = 7 then InDate := InDate - 1;
result := InDate + ((Trunc(((Increment - (6 - DayOfWeek(InDate)))/5) + 0.8)
* 2) + Increment);
end else if Increment if DayofWeek(InDate) = 1 then InDate := InDate + 1;
result := InDate + ((Trunc(((Increment - (2 - DayOfWeek(InDate)))/5) - 0.8)
* 2) + Increment);
end else begin {No Increment}
result := InDate;
end;
end;