It does compile without errors. But does it also run without errors?
datshipmentdate := 01072012D;
intDateDec := 9999;
intDateDec := (CREATEDATETIME(”datShipmentdate”, 0T) - CREATEDATETIME(010180D, 0T)) / 86400000;
MESSAGE(’%1′,intDateDec);
I’ll give the SQL answer (even if SQL has nothing to do with it): it depends.
It works on 4.0SP3 Build 25638,5.0SP1 Build 26084.
It gives an error on 5.0SP1 Build 30488,NAV2009 build 27808,NAV2009SP1 build 29227,NAV2009R2 32228
The error is:
Overflow under type conversion of Decimal to Integer.
Value: 11,869.9583333333333
Other builds I didn’t try, but it is clear that between builds 26084 and 30488 something has changed internally in C/AL.
In the older versions, the result is implicitly converted to an integer but not anymore in the newer versions.
These are 2 versions that work:
datshipmentdate := 01072012D;
intDateDec := 9999;
intDateDec := ROUND((CREATEDATETIME(”datShipmentdate”, 0T) - CREATEDATETIME(010180D, 0T)) / 86400000,1);
MESSAGE(’%1′,intDateDec);
or also:
datshipmentdate := 01072012D;
intDateDec := 9999;
intDateDec := (CREATEDATETIME(”datShipmentdate”, 0T) - CREATEDATETIME(010180D, 0T)) DIV 86400000;
MESSAGE(’%1′,intDateDec);
Читать дальше