Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Monday, July 22, 2013

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) ;
or
days = date2num(Date123) - date2num(Date234);
or
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

#timeConstants

days = DateTimeutil::getDifference(DateTime123, DateTime234) / #secondsPerDay;
-------------------------------------------------------------------
date2num(systemdateget()) - date2num(urtable.date);
---------------------------------------------------------------------------------------------------------
static void DateDiff(Args _args)
{
    TransDate   d1,d2;
    int daysdiff;
    ;
    d1  = 31\12\2010;
    d2  = today();
    daysDiff = d2 - d1;
    info(strfmt("%1",daysDiff));
}
-----------------------------------------------------------------------------------------------------
Or just override the field in datasource level as modified()

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


No comments:

Post a Comment

Get a table ID in SQL - D365

Hi select ID from SysTableIdView where  SysTableIdView .Name = 'CustTable' Regards,