Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Calendar Management Codeunit

(0) ShareShare
ReportReport
Posted on by 1,749

I have written a function to calculate the next working .

My parameters is Fromdate and No of Days .

GetTheNextDay(FromDate : Date;NoofDays : Integer) : Date

ToDate:=0D;
ToDate:=CALCDATE(FORMAT('<'+FORMAT(NoofDays)+'D>'),FromDate);
TempDate.RESET;
TempDate.SETRANGE("Period Type",TempDate."Period Type"::Date);
TempDate.SETRANGE("Period Start",FromDate,ToDate);
IF TempDate.FINDSET THEN BEGIN
REPEAT
  IF (CUCalMgmnt.CheckDateStatus(CompInfo."Base Calendar Code",TempDate."Period      Start",TempDescription)) THEN
 ToDate+=1;
UNTIL TempDate.NEXT =0;
END;
EXIT(ToDate);

Input:27/12/16,5

output:03/01/17;

it is giving one extra day

i have already checked my base calender in which there is only one sunday between my date range.

How is this possible?

*This post is locked for comments

  • Verified answer
    javedakhtar Profile Picture
    javedakhtar 1,749 on at
    RE: Calendar Management Codeunit

    Hello Mohana Sir,

    Thanks for your valuable suggestion i had modified my code and tested with some input and its working fine.

    Working:=0;

    TempDate.RESET;

    TempDate.SETFILTER("Period Start",'>=%1',FromDate);

    TempDate.SETRANGE("Period Type",TempDate."Period Type"::Date);

    IF TempDate.FINDSET THEN  BEGIN

     REPEAT

     IF (NoofDays <> Working) THEN BEGIN

       IF NOT (CUCalMgmnt.CheckDateStatus(CompInfo."Base Calendar Code",TempDate."Period Start",TempDescription))THEN BEGIN

          Working+=1;

          NextDay:=TempDate."Period Start";

       END;

      END

      ELSE

       EXIT(NextDay);

     UNTIL (TempDate.NEXT =0 ) ;

    END;

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,161 Super User 2025 Season 1 on at
    RE: Calendar Management Codeunit

    Do you mean it is working fine?

  • javedakhtar Profile Picture
    javedakhtar 1,749 on at
    RE: Calendar Management Codeunit

    sorry sir i marked 29 as holiday then its showing 020117

  • javedakhtar Profile Picture
    javedakhtar 1,749 on at
    RE: Calendar Management Codeunit

    output is 010117 but its a holiday

  • javedakhtar Profile Picture
    javedakhtar 1,749 on at
    RE: Calendar Management Codeunit

    yes you are right sir ,i have to first confirm whether i want to calculate from today or tomorrow

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,161 Super User 2025 Season 1 on at
    RE: Calendar Management Codeunit

    Check Input:27/12/16,4

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,161 Super User 2025 Season 1 on at
    RE: Calendar Management Codeunit

    no, if 29/12 is non working day?

  • javedakhtar Profile Picture
    javedakhtar 1,749 on at
    RE: Calendar Management Codeunit

    did you mean to say if i mark my today as holiday what will be the output?

  • javedakhtar Profile Picture
    javedakhtar 1,749 on at
    RE: Calendar Management Codeunit

    in calcdate function if give today and 2d it will output.29/12/16

    thats why i used calcdate function to increment my date by 1d

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,161 Super User 2025 Season 1 on at
    RE: Calendar Management Codeunit

    did you check what if Todate after above code is also Holiday?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans