# Date calculation exclude weekend without the use of nav cal.

Hi,

I want to calculate the date excluding weekends (saturday and Sunday) without using
the navision base calender. During counting of days, the starting date should also be included. For example ,If “starting date” = 30.01.2013 and I want to calculate (’+7D’), it should also include date (30.01.2013), then the Ne Date should be 07.02.2013.

It is like that starting date should be taken to the calculation. So, we count 7 days and 1.day: 30.01.13, 2.day: 31.01.13, 3.day: 01.02.2013, (weekend 02.-03.02.2013), 4.day: 04.02.2013, 5.day: 05.02.2013, 6.day: 06.02.2013, 7.day: 07.02.2013.

Below mentioned is my code,
I created a function and passing two parameteds (DatevalueTxt,InitialDate)

Function -->ExcludeWeekends(DateValueTxt : Text[30];InitialDate : Date) : Date
The following variables are used

Name DataType Subtype
Date2 Record Date
Date1 Record Date
DayCount Integer
NewDate Date
DatevalueVar DateFormula

EVALUATE(DatevalueVar,DateValueTxt);
CLEAR(NewDate);
IF (DateValueTxt <>’’) THEN BEGIN
Date2.RESET;
Date2.SETRANGE(“Period Type”,Date2.“Period Type”::Date);
Date2.SETRANGE(“Period Start”,InitialDate,CALCDATE(DatevalueVar,InitialDate));
IF Date2.FINDSET THEN BEGIN
REPEAT
IF Date2.“Period No.” IN [6,7] THEN
DayCount +=1;
UNTIL Date2.NEXT=0;
NewDate := Date2.“Period Start” +DayCount;
Date1.RESET;
Date1.SETRANGE(“Period Type”,Date1.“Period Type”::Date);
Date1.SETRANGE(“Period Start”,NewDate);
IF Date1.FINDFIRST THEN BEGIN
IF Date1.“Period No.” = 6 THEN
NewDate := Date1.“Period Start” + 2;
IF Date1.“Period No.” = 7 THEN
NewDate := Date1.“Period Start” + 1;
END;
END;
END ELSE BEGIN
Date2.RESET;
Date2.SETRANGE(“Period Type”,Date2.“Period Type”::Date);
Date2.SETRANGE(“Period Start”,InitialDate);
IF Date2.FINDFIRST THEN BEGIN
IF Date2.“Period No.” = 6 THEN
NewDate := Date2.“Period Start” + 2
ELSE IF Date2.“Period No.” = 7 THEN
NewDate := Date2.“Period Start” + 1
ELSE
NewDate := InitialDate;
END;
END;
EXIT(NewDate);

I am not getting how to include the starting date, it is calculating SD =08.02.2013, but it should calculate 07.02.2013, if give the values in function–>
ExcludeWeekends(‘7D’,300113D).

Does somebody help in this regard.