Script program Halts with error “Datetime calculation with overflow” resulting in the program not controlling
EcoStruxure Building Operation
Observed in versions 220.127.116.11 and 18.104.22.168
When a script program subtracts one datetime from another it can result in a negative value if the datetime being subtracted (subtrahend) is a later datetime than the one being subtracted from (minuend). This causes the program to halt with error “Datetime calculation with overflow”. The issue can also occur when a script program calls a function that involves a datetime subtraction resulting in a negative value, for example the standard PID function.
The image below illustrates the issue where DT1 is a later time than DT2.
The problem has typically been seen to occur when using the PID function and the ASP is set to obtain updates from an NTP server. The PID function uses the current time and the last time the function was called to calculate the time passed, for example: -
TimePassed = CurrentDate – LastTime
Ignoring the date portion consider the scenario where the ASP time is currently 14:01:00 but is one minute ahead of the actual time of the NTP server. If the function has just been called the LastTime variable will be 14:01:00. However, in the meantime if the ASP time is updated by the NTP server it becomes 14:00:00 and hence when the function is called again the calculation is: -
TimePassed = 14:00:00 – 14:01:00
This results in a negative value halting the program on error “Datetime calculation with overflow”.
Either of the two workarounds below can be used but each will need to be considered based on their overall impact.
- Use the DIFFTIME function
- If calling a function check the subtrahend is not a later datetime than the minuend before calling.
This is reported in defect #50263