How to add days to a date to obtain a date

FlashtnFlashtn Member Posts: 68
Hi Dear Navision Developers,

I want to compare a date1 to other date2 in this manner:
IF date1 < date2 + 30D    //adding 30 days to date2
   ...
END
How can I do this and to to add days to a date to obtain a date ?

Thank you in advance :)

Comments

  • SavatageSavatage Member Posts: 7,142
    IF date1 < (date2 + 30)

    FYI if your using this in payables or receivables or inv, etc etc.

    I would add a field in the appropriate setup table that holds the value of 30. So it can be changeable on the fly if needed.

    example/

    Say this is about some item start date or something.
    add a field to the inv setup table Like Adjust Days
    your code would be something like
    InvSetup.GET;
    If Date1 < (Date2+ Invsetup."Adjust Days").....
  • FlashtnFlashtn Member Posts: 68
    Thank you for your response :D
    But, is not accepted in this codition, an error message appear that indicates that's impossible to evaluate this condition :

    Date AND Integer !!!
  • SavatageSavatage Member Posts: 7,142
    hmm works for me - are you sure date1 & date2 are date fields?
    perhaps you should paste your code

    IF Item."Discontinued Date" < (Item."Start Date" + 30)
    THEN MESSAGE('%1 was not a very good item',"No.");
    
    Seems to work for me :mrgreen:
  • kinekine Member Posts: 12,562
    And what about using CALCDATE function?

    :whistle:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • FlashtnFlashtn Member Posts: 68
    Good Morning,

    My code is:
    IF "Due Date" > ("Due Date"+30D)
       ...
    END
    

    "Due Date" is a field in the "Cust. Ledger Entry" table.
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    Flashtn wrote:
    IF "Due Date" > ("Due Date"+30D)
       ...
    END
    
    the above condition always evaluates to FALSE.

    Try this and the help for CALCDATE will help you.
    // if Date1 < (Date2 + 30D) then
    
    if (Date1 < CALCDATE('+30D',Date2)) then begin 
      ......
      
    end; 
    
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • kinekine Member Posts: 12,562
    Flashtn wrote:
    IF "Due Date" > ("Due Date"+30D)
       ...
    END
    
    the above condition always evaluates to FALSE.

    Try this and the help for CALCDATE will help you.
    // if Date1 < (Date2 + 30D) then
    
    if (Date1 < CALCDATE('+30D',Date2)) then begin 
      ......
      
    end; 
    
    Do not forget about making the code multilanguage enabled and use the <> around the Calcdate expression:
    if (Date1 < CALCDATE('<30D>',Date2)) then begin 
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SavatageSavatage Member Posts: 7,142
    Flashtn wrote:
    My code is:
    IF "Due Date" > ("Due Date"+30D)
       ...
    END
    

    "Due Date" is a field in the "Cust. Ledger Entry" table.

    How can due date ever be Greater than itself plus some more days?
    are you sure one of the "due date" shouldn't be document date or posting date?
    IF Item."Discontinued Date" < (Item."Start Date" + 30) ...
    
    Still worked in my test report - adding 30D instead of just 30 caused an error. Anyway I would still make "30 days" a variable that can be changed from some setup table.

    We do something similar. Even tho an item is discontinued (blocked) we will allow it to be returned for (X) amount of days.

    // CHECK FOR RETURNABLE
    IF (Item.Blocked) AND (Item."Discontinued Date" <> 0D)
     THEN DaysDiscontinued := WORKDATE - Item."Discontinued Date";
    
    InvtSetup.GET;
    IF (("Document Type" IN ["Document Type"::"Return Order","Document Type"::"Credit Memo"]) AND Item."Can Not Return") OR (DaysDiscontinued > InvtSetup."Days Blocked-Not Returnable")
      THEN BEGIN
        IF NOT CONFIRM ('Item Not Returnable. Do you want to add item anyway?')
          THEN BEGIN
                MESSAGE('Please Delete This Item');
          END
      END;
    
    Where (X) is set in the Inventory Setup table in a field called "Days Blocked-Not Returnable". It's set this way just in case we one day want to increase or descrease the allowable time to return a discontinued item.
Sign In or Register to comment.