How Do I Calculate the Difference Between Two Datetime Values? (Magic xpa 4.x)
Finding the differences between two date-time stamps can be a lot of work if you do it manually.
Fortunately, Magic xpa provides a function to treat the date and time as one unit for subtraction. The DifDateTime() function allows you to find the difference between two date-time pairs, as shown in this example.
DifDateTime() returns the number of days and number of seconds that are the difference between the two date-time pairs. You can convert the number of seconds into hours/minutes/seconds by treating it as a time variable and using the Hour(), Minute(), and Second() functions on it (See How Do I Calculate the Hour/Minute/Seconds Portion of a Given Time Value?).
DifDateTime() has the following syntax:
DifDateTime(Date1, Time1, Date2, Time2, DaysVariable, SecondsVariable)
where:
-
Date1, Time1 are the first date-time pair
-
Date2, Time2 are the second date-time pair
-
DaysVariable is the variable reference for the difference in days.
-
SecondsVariable is the variable reference for the difference in seconds.
You will notice in the example that the variables for the last two parameters are entered as variable references. That is, they are written in quotes, followed by the literal VAR: 'E'VAR and 'F'VAR. This is the format Magic xpa uses refer to a variable by address. This is necessary to update the variable from within an expression. Usually Magic xpa only updates variables with an Update operation, but in this case you are updating two variables at the same time so a reference is needed.
The Online and Rich Client Samples projects (program DT07 and RDT07)