Calculating number of Working days in a month

JamieBrown
Member Posts: 107
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.
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
-
You could look at the date functions and calculate it.
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!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 -
You could try something like this:
===============
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);
===============Sunday, Godwin G0 -
DeletedAnalyst 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 -
-
Savatage wrote:http://www.mibuso.com/forum/viewtopic.php?t=2565
CalcDateFormula DateFomula
TargetDate Date
SourceDate Date
CompanyInfo Record Company Information
CalendarMgt Codeunit Calendar Management
NonWorking Boolean
DateDscr Text(30)
TargetDate := CALCDATE(CalcDateFormula,SourceDate);
CompanyInfo.GET;
REPEAT
NonWorking := CalendarMgt.CheckDateStatus(CompanyInfo."Base Calendar Code",TargetDate,DateDscr);
IF NonWorking THEN
TargetDate := CALCDATE('-1D',TargetDate);
UNTIL NOT NonWorking;
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!
NoOfDaysAnalyst 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
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions