Does this code work or not?
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);
Filed under: C/AL, NAV, NAVISION, Uncategorized
[…] Bron : Kriki’s Dynamics NAV blog Lees meer… […]
Hi, Kriki
86400000 is 1 day in milliseconds, right?
Why did you need this calculation?
wouldn\’t be enough just the following:
MESSAGE(\’%1\’,datShipmentdate - 010180D);
I found that code in a customer I technically upgraded from 50SP1 to 2009R2. Suddenly it gave errors on this part. I don’t remember why this code was used but it gave a runtime-error. So I blogged about it.