Count working days between an established range


I have a DATEFORMULA type value that establishes the number of working days and an initial date that establishes the date on which the count begins.
How can I get the amount placed in the DATEFORMULA field and use it to set only working days and from this formula to have a final date?

Best Answer


  • serdarulutasserdarulutas Member Posts: 50
    Here is what I would do.

    If the date formula is "1M", then I'd first calculate the number of days I need.

    EndDate := CALCDATE('1M',TODAY);
    NumberOfDays := EndDate - TODAY;
    MESSAGE(FORMAT(NumberOfDays)); //31 days

    Then I would use the suitable function in CalendarManagement to find the 31st business day at desired calendar code.
  • crosscross Member Posts: 10
    My final date can not be a date that includes weekends. That is, what I need is to make my count based on the days elapsed without including Saturday and Sunday.
    If in the field DATEFORMULA I have 50D, I need to count 50D only seeing Monday, Tuesday, Wednesday, Thursday and Friday. exclude weekends and non-working days.
  • DuikmeesterDuikmeester Member Posts: 304
    aStartDate := WORKDATE;
    aDays := CALCDATE(aDateFormula,aStartDate) - aStartDate; //Count number of days
    aWeeks := ROUND(aDays / 5,1,'<');                        //Count number of weeks (5 workdays per week)
    aDays := aDays MOD 5;                                    //Left over days (6 days = 1 week + 1 day)
    aDays := (aWeeks * 7) + aDays;                           //Total number of days
    aEndDate := aStartDate + aDays;                          //Calculate new date
    MESSAGE('%1 + %2D = %3\\%4',aStartDate,aDays,aEndDate,aDateFormula);
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    That's really great @Duikmeester . I would love to see an addition to your code taking into account holidays. For start a 'global' (not country or company specific) holidays like Good Friday or Easter Monday would be cool...
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.