Difference between two dates in days in Dynamic AX

To get the difference between two dates in dynamics ax just convert the dates into numbers and subtract one from the other. The result would be the amount of days between these dates.

today() – mkdate(31,01,2011) ;
days = date2num(Date123) – date2num(Date234);
TblName.FieldName= date2num(today()) – date2num(AnotherTblName.DatefeildName);

days = date2num(Date123) – date2num(Date234);

To get the difference between two DateTime Values just use the DateTimeUtil Class. The result is the difference in seconds. So just divide these through #secondsPerDay and you’ll get the days


days = DateTimeutil::getDifference(DateTime123, DateTime234) / #secondsPerDay;

date2num(systemdateget()) – date2num(;
static void DateDiff(Args _args)
    TransDate   d1,d2;
    int daysdiff;
    d1  = 31122010;
    d2  = today();
    daysDiff = d2 – d1;
Or just override the field in datasource level as modified()

tablename.fieldName3 = tablename.fieldName2 – tablename.fieldName1;
filedName1 – Out put field,
filedName2 – To date field,
filedName2 – from date field,

Leave a Reply

Your email address will not be published. Required fields are marked *