calcuting date difference between two consecutive dates

I want to calculate the date difference between two posting date on the Cust. Ledger Entry table. how can i achieve this? this is what i have written so far to get what i want but its not working.

steps:="Cust. Ledger Entry".next(1);
steps := "Cust. Ledger Entry1".next();

start := "Cust. Ledger Entry"."Posting date";
"Cust. Ledger Entry1".next();
enddate := "Cust. Ledger Entry1"."Posting Date";

diff := enddate - start;

Comments

  • for example

    31/01/08
    29/02/08
    23/07/08
    28/12/08
  • And where is there your problem?
    If you need the Days between the Start and End you can use also the DATE table
    Do you make it right, it works too!
  • I dont know how to achieve it using the date table. the data set is in a columnar form, taking the one underneath and doing the logic. thats my problem. Can you help me out, please?
  • Hi,

    You will need to give us us a more detailed explaination. It sounds like you want to use a matrix form. Have a look at budgets from 113 or the Howto

    http://www.mibuso.com/howtoinfo.asp?FileID=13
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • I looked into the matrix form but that is not what i want. I am doing this on a report. this report is getting data from the cust. ledger entry table. I want to calculate the number of days between two consecutive posting date. For example, if i have two entries like the ones below

    posting date amount
    01/01/08 1000
    01/04/08 200


    i want something that will give me the days different between

    01/04/08 - 01/01/08

    thanks.. I hope that helps to explain.
  • I just tried on a little testform, and Subtracting 2 DATe variables will give you the number of days in between. You already do that in your code, so what is the problem you are experiencing ?
  • its not working and i can't figure out why?
  • Hi

    Are you doing this in onaftergetrecord of "Cust. Ledger Entry" DataItem?

    Are you getting wrong data(Record) printed on report?

    start := "Cust. Ledger Entry"."Posting date";
    "Cust. Ledger Entry1".next();
    enddate := "Cust. Ledger Entry1"."Posting Date";

    diff := enddate - start;


    By looking at code posted by you, it must have been printing the every second record.
    If you are trying to print every record then you have to use

    start := "Cust. Ledger Entry"."Posting date";
    IF "Cust. Ledger Entry1".next() THEN BEGIN
    enddate := "Cust. Ledger Entry1"."Posting Date"
    diff := enddate - start;
    "Cust. Ledger Entry1".next(-1) // This is to take the Pointer back by one
    END ELSE BEGIN
    diff := 0;
    END;


    Regards

    Harjot
  • Yes i am doing it on after get record and its displaying wrong duration. I tried your version but its diplsying sn error of integer to boolean telling me it should have true/false on this line
    IF "Cust. Ledger Entry1".next() THEN BEGIN
    thanks
  • Hi

    Sorry my mistake

    Change the Line
    IF "Cust. Ledger Entry1".next() THEN BEGIN

    To

    IF "Cust. Ledger Entry1".next() <> 0 THEN BEGIN

    Regards

    Harjot