How to increment a Date field?

Aravindh_NavisionAravindh_Navision Member Posts: 258
Hi Pals,

I need to increment date by 1 month each from a given date for 12 month. I am doing this in report in OnPreReport() trigger.

For eg.: Date input: 01/03/2012. (1st month)

It should get increment by 1 month (for 12 months).

01/04/2012 (2nd month)
01/05/2012 (3rd month)
-
-
-
01/13/2013 (12th month)

Can anyone help me how to do it?

Thanks in advance,
Aravindh

Answers

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Check Report 120 how Date is calculated based on Period Length
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Thanks for you reply Mohana. May I know the report name? Report 120 is not there in my DB.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Aged Accounts Receivable...I am using IN Version of 2009 R2..
  • sameerarsameerar Member Posts: 63
    Define Global Variables PeriodLength as DateFormula
    NewDate as Date
    Eg

    EVALUATE(PeriodLength,'1M');
    NewDate := CALCDATE(PeriodLength,140212D);
  • SogSog Member Posts: 1,023
    sameerar wrote:
    Define Global Variables PeriodLength as DateFormula
    NewDate as Date
    Eg

    EVALUATE(PeriodLength,'1M');
    NewDate := CALCDATE(PeriodLength,140212D);

    This is language dependent! Although month is often translated to another word starting with an m there is no guarantee that it always will.

    Language independent version:
    EVALUATE(PeriodLength,'<1M>');
    NewDate :=   CALCDATE(PeriodLength,140212D);[/
    

    also read up on dateformulas and maybe even the virtual Date table.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Actually this is working. But where I got struck is displaying the date for 1 month interval up to NoofTimes.

    Variables

    The below inputs I will give in report's request form.

    NoofTimes - integer
    DueDate - date

    I wrote the below coding in OnPreReport().
    boolDate := FALSE;
    
    FOR intI := 1 TO NoofTimes DO BEGIN
      IF DocumentType = DocumentType::"Posted Invoice" THEN BEGIN
        CLEAR(NewDueDate);
        IF boolDate THEN BEGIN
          EVALUATE(PeriodLength,'1M');
          NewDueDate := CALCDATE(PeriodLength, DueDate);
          recSalesHeader."Due Date" := NewDueDate;
          MESSAGE('%1', NewDueDate);
        END ELSE BEGIN
          recSalesHeader."Due Date" := DueDate;
          MESSAGE('%1', DueDate);
        END;
      END;
      boolDate := TRUE;
    END;
    

    For example:

    Input:

    NoofTimes = 5
    DueDate = 01/03/2012

    I am getting the correct values for 1st and 2nd. From 3rd to 5th I am getting the same value which is same as 2nd which is wrong. That is..
    1. 01/03/2012
    2. 01/04/2012
    3. 01/04/2012
    4. 01/04/2012
    5. 01/04/2012
    

    I must get..
    1. 01/03/2012
    2. 01/04/2012
    3. 01/05/2012
    4. 01/06/2012
    5. 01/07/2012
    

    What to do to get this?
  • sameerarsameerar Member Posts: 63
    Hint - "boolDate"
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    The Reason is DueDate is not Updating every time
    Try this code
    boolDate := FALSE;
    
    FOR intI := 1 TO NoofTimes DO BEGIN
      IF DocumentType = DocumentType::"Posted Invoice" THEN BEGIN
        CLEAR(NewDueDate);
        IF boolDate THEN BEGIN
          EVALUATE(PeriodLength,'1M');
          NewDueDate := CALCDATE(PeriodLength, DueDate);
          DueDate := NewDueDate; // New Code
          recSalesHeader."Due Date" := NewDueDate;
          MESSAGE('%1', NewDueDate);
        END ELSE BEGIN
          recSalesHeader."Due Date" := DueDate;
          MESSAGE('%1', DueDate);
        END;
      END;
      boolDate := TRUE;
    END;
    
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Thats fantastic. \:D/ It is working fine and getting the desired output. :D

    :thumbsup: Thanks a lot Mohana, Sameer, Sog for your replies and help.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Thats fantastic. \:D/ It is working fine and getting the desired output. :D

    :thumbsup: Thanks a lot Mohana, Sameer, Sog for your replies and help.

    welcome :)
Sign In or Register to comment.