Calculate date

Navi_LearnerNavi_Learner Member Posts: 356
Hi I have a question. In our current Cash report, we have the posting date, and the due date. How to calculate the days when custoer pay the cash, i.e due date - posting date. I tried it, but it didn't work. Thanks in advance!

Comments

  • AlishaAlisha Member Posts: 217
    "Due date" - "Posting date" should work fine. It returns an integer, which is the number of days between both dates.
  • Navi_LearnerNavi_Learner Member Posts: 356
    I create a variable with integer data type, but when I minus the two, the result is zero. So how can I get the correct number? Thanks!
  • DenSterDenSter Member Posts: 8,307
    That's because your dates are the same? When I do Date1 - Date2 I get an integer with the number of days, I don't know how else to put it.
  • DenSterDenSter Member Posts: 8,307
    I had created a little form to test it myself, and figured maybe you'd want to see how I got it to work:
    OBJECT Form 50000 Date Minus Date
    {
      OBJECT-PROPERTIES
      {
        Date=01/19/06;
        Time=12:24:17 PM;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=5610;
        Height=2200;
        OnOpenForm=BEGIN
                     Date2 := TODAY;
                     Date1 := CALCDATE('<-10D>',Date2);
                   END;
    
      }
      CONTROLS
      {
        { 1000000000;TextBox;3630 ;220  ;1700 ;440  ;CaptionML=ENU=Date 1;
                                                     SourceExpr=Date1 }
        { 1000000001;Label  ;220  ;220  ;3300 ;440  ;ParentControl=1000000000 }
        { 1000000002;TextBox;3630 ;770  ;1700 ;440  ;CaptionML=ENU=Date 2;
                                                     SourceExpr=Date2 }
        { 1000000003;Label  ;220  ;770  ;3300 ;440  ;ParentControl=1000000002 }
        { 1000000004;CommandButton;220;1430;5060;550;CaptionML=ENU=Date 2 Minus Date 1;
                                                     OnPush=BEGIN
                                                              MyInteger := Date2 - Date1;
                                                              MESSAGE(FORMAT(MyInteger));
                                                            END;
                                                             }
      }
      CODE
      {
        VAR
          Date1@1000000000 : Date;
          Date2@1000000001 : Date;
          MyInteger@1000000002 : Integer;
    
        BEGIN
        END.
      }
    }
    
    Save it in a text file and import it into Navision. It's a form with object number 50000. If that number is already taken, just change the number to one that is available.
  • Navi_LearnerNavi_Learner Member Posts: 356
    I don't have the liscence to import the file. I changed something. Now almost all the number are -30 whether it is paid before the due date or after the due date except the number that is paid at exact due date is correct that is zero. I still don't why. Can it give me for instance 20, 8 and etc after I minus the two date?
  • DenSterDenSter Member Posts: 8,307
    I really don't know how else to explain it.... You subtract two dates and it returns an integer. This works all the time. If date 1 is before date 2 it returns a positive number, a negative number if it's after date 2, and zero if it's the same.

    If you're not getting the right results then you're not programming it correctly. If it's in a report you typically want to do this in the OnAfterGetRecord trigger of the relevant dataitem. You can even put the source expression of the control to be "Posting Date" - "Due Date" and it will show the number.
  • SavatageSavatage Member Posts: 7,142
    post your code, variables, where you're doing this & what trigger you are using. then we can see where you are going wrong.
Sign In or Register to comment.