DateFormula wrong number of days

Help please, what am I missing?.

I am trying to get an end date but it is not correct due I suspect to the different number of days from June to March as per the example below:

“End Date” = 30/06/13

“S.Term” = 3M

StartDate should be 01/04/13 but is calculated as 31/03/13

Code: Navision 3.7

( “S.Term” = DateFormula)

TermText := FORMAT(“S.Term”);

IF TermText <> ‘’ THEN BEGIN

IF “End Date” <> 0D THEN BEGIN

TermText := ‘-’ + TermText;

StartDate := CALCDATE(TermText,“End Date”);

StartDate := CALCDATE(’+1D’ , StartDate);


I think

StartDate := CALCDATE(’+1D’ , StartDate);

is not required.

You are calculating date 3 months before, which will be 30/03/2013 in your example case, if you want to know a day 90 days before then instead of ‘-3M’ use, ‘-90D’.

If you want the last day of the month as the end date, use CM

TermText := ‘-’ + TermText;

StartDate := CALCDATE(TermText,“End Date”);

StartDate:= Calcdate(‘CM’, StartDate);

If you want the first day of the month, then just find the last day using CM and add a day.

The code may not be as graceful as I could do if I put time into it but the basic idea is there.