9.33 DATEDIFFERENCE
Calculates the difference between two given dates in number of days. The return code indicates if the format of the dates or the dates themselves are valid (Y or N). The sign of the calculated value may also be returned.
Arguments
No | Type | Req/ Opt | Description | Min Len | Max Len | Min Dec | Max Dec |
|---|---|---|---|---|---|---|---|
1 | N | Req | Start/First date. See Note. | 6 | 8 | 0 | 0 |
2 | A | Req | Format of Start/First Date | 1 | 1 | ||
3 | N | Req | End/Second date. See Note. | 6 | 8 | 0 | 0 |
4 | A | Req | Format of End/Second Date | 1 | 1 |
Valid Date Formats
Valid formats for first and second dates: A, B, D, F, H, J, L, V and 1.
Refer to Date Formats
Note:
For the first and the third argument, the INTEGER and FLOAT field cannot be used.
The DATE field can be used, but it should first be converted into string using the .AsNumber Intrinsic Function.
The value of the second and the fourth argument must be in sync with the format that is put into the intrinsic function.
For example, if you have a DATE field called DATEFL1, and want to use it in the BIF as the first argument, you must do a conversion like this:
DATEFL1.AsNumber(DDMMCCYY) (Refer to the Intrinsic Function for other formats.)
In this example, the value of the second argument should be H, which indicates the DDMMYYYY date format.
To hold the first return value, any NUMERIC field can be used including INTEGER and FLOAT.
Example RDMLX only:
USE BUILTIN(DATEDIFFERENCE_ALPHA) WITH_ARGS(#DATEFL1. AsNumber(DDMMCCYY) H #DATFL2. AsNumber (CCYYMMDD) J)TO_GET(#DEC80 )
Return Values
No | Type | Req/ Opt | Description | Min Len | Max Len | Min Dec | Max Dec |
|---|---|---|---|---|---|---|---|
1 | N | Req | Difference (beg to end) in days | 3 | 8 | 0 | 0 |
2 | A | Opt | Sign of difference (+,-) | 1 | 1 | ||
3 | A | Opt | Return code (Y, N) for complete. | 1 | 1 |
Example
Calculate the difference #DIFF in days between date field #YMD in date format YYMMDD (D) and date field #DMY in date format DDMMYY (B):
USE BUILTIN(DATEDIFFERENCE) WITH_ARGS(#YMD D #DMY B)
TO_GET(#DIFF #SIGN)