Slight problem Calculating No. of working days...
JamieBrown
Member Posts: 107
Hi, I have the following code calulating the number of working days in a calendar month. This works fine apart from when the enddate = nonworking. This makes noofdays 1 too many. Would I need, if the enddate = nonworking then noofdays := noofdays -1? (Noofdays is a boolean)
As you can tell, I'm still fairly new to Navision, so I hope this makes sense...
Thanks in advance.
As you can tell, I'm still fairly new to Navision, so I hope this makes sense...
Thanks in advance.
Form - OnInit()
d := TODAY;
datetoday := DATE2DMY(d,1);
Startdate := CALCDATE('-CM',WORKDATE);
enddate := CALCDATE('CM',WORKDATE);
companyinfo.GET;
REPEAT
nonworking := calendarMgt.CheckDateStatus(companyinfo."Base Calendar Code",Startdate,datedscr);
IF NOT nonworking THEN
noofdaysTD := noofdaysTD + 1;
Startdate := Startdate + 1;
UNTIL Startdate >= d;
noofdaysTD := noofdaysTD +1;
Startdate := CALCDATE('-CM',WORKDATE);
enddate := CALCDATE('CM',WORKDATE);
companyinfo.GET;
REPEAT
nonworking := calendarMgt.CheckDateStatus(companyinfo."Base Calendar Code",Startdate,datedscr);
IF NOT nonworking THEN
noofdays := noofdays + 1;
Startdate := Startdate + 1;
UNTIL Startdate >= enddate;
noofdays := noofdays + 1;
dateperc := ROUND(noofdaysTD / noofdays * 10000,1);
0
Answers
-
Why don't you use the date table? You can set the filters and loop through the record, seeing if it is a working day and count them.0
-
[You are adding a "non conditional" day on at the end, so you need to check if the last day is a workingday then add the extra day!
Startdate := Startdate + 1;
UNTIL Startdate >= enddate;
nonworking := calendarMgt.CheckDateStatus(companyinfo."Base Calendar Code",Endingdate,datedscr);
IF NOT nonworking THEN
noofdays := noofdays + 1;Analyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com0 -
The public holidays will be entered manually into the base calendar table as non-working days.
Basically, we're closed on Saturdays and bank holidays. So if either of these fall on the last day of the month it will report incorrectly.
To get around the Saturday problem is straight forward with:sat := DATE2DWY(enddate, 1); If sat = 6 then begin noofdays := noofdays -1; end;
However, I'm not sure how the public holidays would work? Maybe we could just live with it?0 -
Sorry David, I didn't see all of your reply...
Yes your logic was right. It works with the following:Startdate := Startdate + 1; UNTIL Startdate >= enddate; nonworking := calendarMgt.CheckDateStatus(companyinfo."Base Calendar Code",Startdate,datedscr); IF nonworking THEN noofdays := noofdays -1;
Thanks alot for your help.
Jamie0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
