Working Days in Date Calculation
The codeunit 99000755 CalendarManagement manages the calculation of dates using all sorts of calendars; it is a very complex, usable but complex codeunit.
Take a look to this post: “Working days only in date calculation” https://dynamicsuser.net/nav/f/developers/10141/working-days-only-in-date-calculation
Codeunit 99000755 CalendarManagement and Codeunit 7600 Calendar Management à Function “CalcDateBOC”
If you need to calculate dates easily by using a work schedule, you can use a codeunit that uses the virtual table Date and Calendars.
A simple function to calculate Date: “Calc5”
The simple “ExitDate” function could be useful to easily calculate “n-business days” from a certain date.
The core is one of the three functions called “Calc*”; the function works on the “date” virtual table. Filtered as Type Date = Date and Period Number from 1 to 5 (excluding Saturdays and Sundays for example).
Starting from a certain date (in our case WORKDATE + 1, then tomorrow), the records are read based on how many working days they want to calculate.
When the counter reaches the required number of days, the calculated date is returned.
NB: Since there may be days of work absence, which must be stated in the company’s basic calendar, each date reads is verified that it is work and the counter increases accordingly (using the calendar movements table).
It’s a simple codeunit to use a working calendar instead if standard calendar.
Codeunit 50000 “Calculate Shipment Date Work D”
Function “Calc5” (calculate five working days from starting date)
Download Working Days in Date Calculation
“HOW-TO”: Example of utilization:
FROM ORDER LINE > “Calculate Shipment Date” (from Working Days- infinite loading)
SHIPMENT DATE > IS CALCULATED
a more simple example…
CalcNextWorkingDay(StartDate : Date;Days2Add : Integer) : Date
InGG :=0;
RcData.RESET;
RcData.SETRANGE(“Period Type”,RcData.”Period Type”::Date);
RcData.SETFILTER(“Period Start”,’%1..%2′,StartDate,EndingDate);
RcData.FINDSET;
REPEAT
IF NOT CalendarMgmt.CheckDateStatus(CodiceCalendarioBase,RcData.”Period Start”,Description) THEN
InGG += 1;
UNTIL (RcData.NEXT = 0) OR (InGG = Days2Add);
EXIT(RcData.”Period Start”);