Calculating number of Working days in a month

JamieBrownJamieBrown Member Posts: 107
edited 2006-04-20 in Navision Attain
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.

Comments

  • David_CoxDavid_Cox Member Posts: 509
    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.com
  • sggsgg Member Posts: 109
    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 G
  • David_CoxDavid_Cox Member Posts: 509
    edited 2006-04-20
    Deleted
    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.com
  • David_CoxDavid_Cox Member Posts: 509
    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!
    NoOfDays
    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.com
Sign In or Register to comment.