Calculating dates

viriatoviriato Member Posts: 105
Hi,

I'm looking for suggestion to calculate a certain day of the month to the end of the month.

Example: 15th of June

StartDate : 15th of June

EndDate: Last day of June ---> how do I calculate this date?


Thanks.

Answers

  • garakgarak Member Posts: 3,263
    Here is calcdate your "friend".

    You need the last day of a month based on a certain day.
    //120708D can also be a datevariable
    
    EndDateofMonth := calcdate('<CM>',120708D);
    BeginDateofMonth := calcdate('<-CM>',120708D);
    
    EndDateofNextMonth := calcdate('<CM+1M>',120708D);
    BeginDateofNextMonth := calcdate('<-CM+1M>',120708D);
    

    Regards
    Do you make it right, it works too!
  • viriatoviriato Member Posts: 105
    Thanks I'm going to try this out.
  • garakgarak Member Posts: 3,263
    Do this, and welcome ;-)
    Do you make it right, it works too!
  • DenSterDenSter Member Posts: 8,305
    EndDateofNextMonth := calcdate('<CM+1M>',120708D);
    BeginDateofNextMonth := calcdate('<-CM+1M>',120708D);
    
    Are you sure? End day of next month is +1M+CM. Do CM in February, you get Feb 28, you add 1M, you get March 28, which is not the last day of march. I didn't try it though, so it might work.
  • garakgarak Member Posts: 3,263
    Oh yes, sorry (i doesn't test it before in NAV) :oops: :oops:

    The correct syntax for EndDateofNextMonth is
    EndDateofNextMonth := calcdate('<1M+CM>',120708D);
    

    So with this, the End date of next month will be correct calculated
    Do you make it right, it works too!
Sign In or Register to comment.