Calculate last working date in a month

TiwazTiwaz Member Posts: 98
edited 2017-01-30 in NAV Three Tier
Hello guys.
I have some trouble using CalcDateBOC and CheckDateStatus functions in codeunit 7600. I am not sure how to use them.
How can I calculate what is the last working date in a month?
For example, if customer validates payment date to be 12.1.2017. then in a field "Last date" it should validate 31.1.2017..
Thanks

Answers

  • RockWithNAVRockWithNAV Member Posts: 1,139
    You tries this

    CALCDATE ('<CM>', Today).
  • RockWithNAVRockWithNAV Member Posts: 1,139
    edited 2017-01-30
    DateVariable := CALCDATE ('<CM>', Today).

    Hope you had understood.
  • TiwazTiwaz Member Posts: 98
    Yeah, but that way which ever date I validate in CALCDATE('<CM>',SomeDate) I will only get last day of that month. What I need is last working date.
    For example, for January 2017 it is 31st but for July 2016 it is not 31st but 29th.
  • Cem_KaraerCem_Karaer Member Posts: 281
    Hi,

    You need a calender or an assuption to determine the working days. Your first step should be to find the last date of the month using <CM> thing, and then you should step backwards with <-1D> and check if the current date is a workday or not.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • zohaibu95@hotmail.comzohaibu95@hotmail.com Member Posts: 223
    Hi,
    First of all you need to setup the base calendar in which you will tell the working and non working days.
    Then you can check the last working using CALCDATE with the express <-1D>
    Best Regards
    Zohaib Ahmed
    Dynamics NAV ERP Technical Consultant.

    please like / agree / verify my answer, if it was helpful for you. thanks.
  • HannesHolstHannesHolst Member Posts: 119
    edited 2017-01-31
    Hi there,

    NAV provides a virtual Date-Table:
    https://msdn.microsoft.com/en-us/library/dd355175(v=nav.90).aspx

    At first, select the Days only by filtering:
    SETRANGE("Period Type", "Period Type"::Date);

    Then filter the current month:
    SETRANGE("Period Start", CALCDATE('<-CM>', TODAY), CALCDATE('<CM>', TODAY));

    --> the filter should be 01012017..31012017 (I don't have a dev-client right now to verify the DateExpression :smile:)

    and then for the Period No. which represents the days in the week:
    SETRANGE("Period No.", 1..5); // Monday to Friday

    Then execute a FINDLAST and you will have the last week day of a month which normally represents the last working day of a month.

    If you want to go a step further with that implementation, you must check the setup of the Base Calendar in NAV (and which Base Calendar you want to use). The table structure of the Base Calendar is similar to the virtual Date-table, but as a benefit it contains the field "Nonworking". The field could be used to identify public holidays.

    Cheers,
    Hannes
Sign In or Register to comment.