How to get the difference between two dates

I want to get the diffference between two dates

for ex 1st date 31/01/2011

2nd date is today

result should be 9 days

How to get this in AX ?

Thanks in Advance

today() - mkdate(31,01,2011) ;

Thanks for ur reply…

if it s today - transdate?

It will work. Just subtract both the dates as suggested by Kranthi.

In mkdate(day, month, year). Here how will i pass transdate?

Transdate d;

;

d= 31\12\2010;

today() - d;

:frowning:

This is not my requirement. I want to take the transdate from custtrans table.

today() - CustTrans.transdate;

Could you elaborate more ?

today() - CustTrans.transdate;

Hi monika this s not correct…

What is your problem in that?

If i write like this

Date invoicedate;

;

invoicedate = today() - custTrans.TransDate;

error

operand ttypes are not compatible with the operator

Hi,

try this…

static void DateDiff(Args _args)
{
TransDate d1,d2;
int daysdiff;
;
d1 = 31\12\2010;
d2 = today();
daysDiff = d2 - d1;
info(strfmt("%1",daysDiff));
}

Naresh

It will return an integer not the date. Here you are trying to find out the difference between two dates - the interval - which will return an integer and not the date…

Hai Praveen,

date2num(systemdateget()) - date2num(urtable.date);

Hope it will help

Regards

Shon[Y]

invoicedate = today() - custTrans.TransDate;

Difference will return an integer not a date. Thats why u r getting an error.

Thanks to all…

Hi Praveen,

You just change the ‘invoicedate’ datatype as–> int

for ex 1st date 31/01/2011

date2num(date1) - date2num(date2)

U will result in number

Try in this format Reply me after trying this.

How get difference amount various dates ex SO date(SalesTable -table) - invoice date(CustInvoiceTrans- table)

and i require it in sales line table so i am trying to write a method here

Thanks in advance

Hi …

i am new of dynamics ax …

i have one doubt;;;;

if … from date and to date datas having from tables…

example’;

fromdate: 10.03.2016

tadate: 12.03.2016

command button (calculate)

result: 2

i need coding about this concept… in clicked method

Thanks