Hi,
Does anyone know how I would go about calculating the number of 'Working' Days in a calendar month? (We're closed Saturdays) Base Calendar does reflect this.
I would imagine the CalendarMgt Codeunit would be used. But how?
I basically need this to be able to report the percentage of time lapsed in a month for company targets?
Thanks in advance.
0
Comments
Take the 1st Day of the StartDate filter By StartDate:=GETRANGEMIN("Date Filter"); then the last day of Date Filter EndDate:=GETRANGEMAX("Date filter"), work out the Number of days, EndDate - StartDate find the first day Day := DATE2DWY(1,StartDate) which will return an Integer for the day I think the week starts as Sunday; 0 = Sunday 1 = Monday Check the Help.
Then you should be able to work out how many Workdays in the given period.
Have a play and try!
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
===============
Function GetDaysInMonth(MonthNo,YearNo) Return=DaysInMonth
Variables:
MonthBegin=Integer
MonthEnd=Integer
cDay=Date
DaysInMonth=Integer
CalMgt = CodeUnit:Calendar Management
DescriptionText=Text(50)
CalendarCode=Code(10)
MonthBegin := calcdate('-CM',DMY2DATE(1,MonthNo,YearNo));
MonthEnd := calcdate('CM',DMY2DATE(1,MonthNo,YearNo));
DaysInMonth := 0;
cDay := MonthBegin;
repeat
if not CalMgt.CheckDateStatus(CalendarCode,cDay,DescriptionText) then
DaysInMonth += 1;
cDay := CalcDate('+1D',cDay);
until(cDay > MonthEnd);
Exit(DaysInMonth);
===============
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
http://www.BiloBeauty.com
http://www.autismspeaks.org
Cool :whistle: its almost what he wants but the code exits on the first nonworking day so!
CalcDateFormula DateFomula
StartDate Date
EndDate Date
NoOfDays Integer
CompanyInfo Record Company Information
CalendarMgt Codeunit Calendar Management
NonWorking Boolean
DateDscr Text(30)
StartDate := CALCDATE('-CM',WORKDATE);
EndDate := CALCDATE('CM',WORKDATE);
CompanyInfo.GET;
REPEAT
NonWorking := CalendarMgt.CheckDateStatus(CompanyInfo."Base Calendar Code",StartDate,DateDscr);
// Add a day if its a working day
IF NOT NonWorking THEN
NoOfDays := NoOfDays + 1;
//increment the StartDate
StartDate := StartDate + 1;
UNTIL StartDate >= EndDate;
//Then you have the working days!
NoOfDays
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com