Date - caliculation - month february

roshiniroshini Member Posts: 122
Hi Nav Experts!

Good Morning!

I am facing one problem with month february by using CALCDATE function.

I am using CALCDATE function to get result of duedate + No. of months

InvDate:= 290208D;
GraceDate:= CALCDATE('1M',InvDate);

it is showing result as 29/03/2008

but I want result as 31/03/2008,

How can get that result ??

with CALCDATE function there is no issue with other months, only with febraury.

Kindly advise me how to handle this problem.

Comments

  • garakgarak Member Posts: 3,263
    The formula <1M> mean, that you want as result a date one mont ago from base date. So it's right that you get the 29.03.2008.
    If you test it with 04.03.2008 you get the 04.04.2008. If you mean, that you need the Enddate of the following Month, use
    CALCDATE('<1M>+<CM>',InvDate)
    

    Regards
    Do you make it right, it works too!
  • roshiniroshini Member Posts: 122
    Excellent ! Mr. Garak,

    Thanks a lot !! I thought by using DATE2DWY (Date) function can solve my problem.

    If I want to concatenate with field then how to write code

    dategrace:= format(paymentdate);
    date1:=dategrace+'M'
    payment2:= CALCDATE(date1, MonthStartDate);

    means I want to add CALCDATE('<1M>+<CM>',InvDate) to the above code.

    or I need write long code for validating february month.
  • kinekine Member Posts: 12,562
    or you can use something like:
    payment2:= CALCDATE('<'+FORMAT(MonthCount)+'M+CM>', MonthStartDate);
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • roshiniroshini Member Posts: 122
    Mr. Kine,

    Great! Thanks a lot....
  • MonstaMonsta Member Posts: 38
    kine wrote:
    or you can use something like:
    payment2:= CALCDATE('<'+FORMAT(MonthCount)+'M+CM>', MonthStartDate);
    

    alternative variant:
    payment2:= CALCDATE(STRSUBSTNO('<%1M+CM>',MonthCount), MonthStartDate);
    
    :)
  • kinekine Member Posts: 12,562
    Monsta wrote:
    kine wrote:
    or you can use something like:
    payment2:= CALCDATE('<'+FORMAT(MonthCount)+'M+CM>', MonthStartDate);
    

    alternative variant:
    payment2:= CALCDATE(STRSUBSTNO('<%1M+CM>',MonthCount), MonthStartDate);
    
    :)
    Better one... =D>
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.