DateTime calculations

Attribute(s)

Date/Time Fields

Description

When performing calculations with date/time field, only reference the field once, store it in a variable and use that variable for the calculation

Motivation

Referencing a date/time field more than once can cause problems since its return value may change between the references

Example / Details

When an agent starts just before midnight, it is possible that the day value is eg. 10 for the tenth day of the month. After getting the field value for a second time, it may suddenly be 11 since the time is not after midnight. Using a time value in this construction results in a second value that is less than the first value, where you should safely assume that it is always bigger.
As an example, avoid this:
varHour := @Hour(fldDate1);
varMin := @Minute(fldDate1);
varSec := @Second(dlfDate1);
Instead, fill a variable and use that for the calculation:
varDate1 := fldDate1;
varHour := @Hour(varDate1);
etc...