- All Categories
- 73 General
- 73 Announcements
- 66.5K Microsoft Dynamics NAV
- 18.6K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 115 Navision DOS
- 854 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 615 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 286 Dynamics CRM
- 109 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 993 SQL General
- 384 SQL Performance
- 34 SQL Tips & Tricks
- 34 Design Patterns (General & Best Practices)
- Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.7K General
- 1.1K General Chat
- 1.6K Website
- 79 Testing
- 1.2K Download section
- 23 How Tos section
- 259 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

Options

misadministrator
Member Posts: **11**

Hi

I'm wanting to populate a variable on a report with the completion date of an installation. I have the fields "Installation Date" and "Engineers Time On Site", where "Engineers Time On Site" is of type Decimal and shows the number of days a job is schedued to run (0.5, 1, etc...)

At first, I simply coded:

roundup:= ROUND("Engineers Time On Site", 1, '>');

completionDate:= "Installation Date" + roundup - 1;

But realised, that this doesn't take any account of weekends and is therefore incorrect!

How do I write a routine to recognise weekdays/weekends?

Many Thanks

- R

I'm wanting to populate a variable on a report with the completion date of an installation. I have the fields "Installation Date" and "Engineers Time On Site", where "Engineers Time On Site" is of type Decimal and shows the number of days a job is schedued to run (0.5, 1, etc...)

At first, I simply coded:

roundup:= ROUND("Engineers Time On Site", 1, '>');

completionDate:= "Installation Date" + roundup - 1;

But realised, that this doesn't take any account of weekends and is therefore incorrect!

How do I write a routine to recognise weekdays/weekends?

Many Thanks

- R

0

## Comments

30You can try something like that, against the virtual table date:

SetRange("Period Type", 0);

SetRange("Period Start", startDate, endDate);

SetFilter("Period No.", '%1|%2', 6,7);

weekEndDays := Count;

-- Alejandro --

12,562As you can see, it can use two calendars to calculate the date...

MVP - Dynamics NAV

My BLOG

NAVERTICA a.s.

11Thanks Alejandro, but there's a problem. I don't have an endDate until after I've worked out weekEndDays. Could I do something like:

SetRange("Period Type", 0);

SetFilter("Period No.", '%1|%2|%3|%4|%5', 1,2,3,4,5);

Then find the record in Date that matches "Installation Date", and do a 'Next' loop to add ("Engineers Time On Site" - 1) to it.

Think this would work, but I don't know how to code it. Any suggestions?

- R

12,562MVP - Dynamics NAV

My BLOG

NAVERTICA a.s.

11- R

2,998"Never memorize what you can easily find in a book".....Or Mibuso

My Blog

55CalcEndDate(SDate : Date;NumberofDays : Integer;VAR EDate : Date;VAR CalendarDays : Integer;VAR TxtDayWeek : Option)

IF SDate =0D THEN

EXIT;

IF NumberofDays <0 THEN

EXIT;

WorkingDate :=SDate;

FOR Count :=1 TO NumberofDays

DO BEGIN

WorkingDate :=CALCDATE('1D',WorkingDate);

DayWeek :=DATE2DWY(WorkingDate,1);

IF DayWeek =6 THEN WorkingDate := CALCDATE('2D',WorkingDate);

IF DayWeek =7 THEN WorkingDate := CALCDATE('1D',WorkingDate);

END;

TxtDayWeek :=DATE2DWY(WorkingDate,1);

EDate :=WorkingDate;

CalendarDays :=WorkingDate - SDate;

8,304Daniel RimmelzwaanRIS Plus, LLC

MVP - Business Apps

2,99801/01/10 plus CM + 15D and the result was 08/03/10 (ggmmaa format)...nonworking days are only sat&sunday + only one monday

"Never memorize what you can easily find in a book".....Or Mibuso

My Blog

2,998a bit crappy...especially if i have to fulfill the following conditions about payment terms!

Pay at the fifteenth working day of the next month :shock: :-k

"Never memorize what you can easily find in a book".....Or Mibuso

My Blog

2,998in the italian module we have a table, payment lines, that stores multiple due dates for the payment, based on some dateformulas...i think i have to split the "JustDoACalcdate" part from the "CalcdateWithWorkingDaysOnly" part, and then calculate the due date by apply the CALCDATE first and the CalcDateBOC on the first "CALCDATED" due date...hope to be clear...

"Never memorize what you can easily find in a book".....Or Mibuso

My Blog

19// Input parameters are StartDate and WorkDays which is number of workdays which you have to add to StartDate

wd := DATE2DWY(StartDate,1); // Get day of week, 1 for monday, 2 for tuesday, etc...

TotalDays := WorkDays+((WorkDays+wd-1) DIV 5) * 2; // add all intermediate saturdays and sundays

IF(wd > 5) THEN // in case start date is saturday or sunday we have to go back a little

TotalDays -= (wd - 5);

EndDate := StartDate + TotalDays; // add totaldays to startdate

Regards,

2,998Thanks, anyway!

"Never memorize what you can easily find in a book".....Or Mibuso

My Blog