Count working days between an established range

cross
Member Posts: 10
Hello,
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?
0
Best Answer
-
You cannot do that with CALCDATE function, it is not aware of 'weekends' or 'holidays' concepts.
Look into Calendar Management codeunit instead, there are functions in there which could help you achieve what you want. Examples of use are in T37/T39, CalcPlannedShptDate
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035
Answers
-
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.0 -
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.0 -
You cannot do that with CALCDATE function, it is not aware of 'weekends' or 'holidays' concepts.
Look into Calendar Management codeunit instead, there are functions in there which could help you achieve what you want. Examples of use are in T37/T39, CalcPlannedShptDate
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035 -
EVALUATE(aDateFormula,'<+10D>'); 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);
1 -
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-031
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