$Sir DateDif: Difference between revisions
m (test modify category) |
m (test modify category) |
||
Line 80: | Line 80: | ||
</ul> | </ul> | ||
[[Category:$Functions]] | [[Category:$Functions|$Sir_DateDif]] | ||
[[Category:Sir2000 User Language Tools $functions]] | [[Category:Sir2000 User Language Tools $functions]] |
Revision as of 17:51, 24 September 2015
Difference between two dates
Note: This $function require the Sir2000 User Language Tools product.
The $Sir_DateDif function expects a datetime format string and two datetime value strings. It accepts a second optional datetime format string, an optional CENTSPAN value, and an optional error control string.
$Sir_DateDif subtracts the second datetime value from the first
datetime value, returning the number of complete days of difference.
If an error is detected, the value 99999999
is returned.
Syntax
%dif = $Sir_DateDif(fmta, data, fmtb, datb, [span], [errctl])
Where:
fmta | First datetime format string. Refer to Datetime string formats for an explanation of valid datetime formats and valid datetime values. Strict matching is used for fmta. |
---|---|
data | First datetime value string. |
fmtb | Optional second datetime format string; the default is to use fmta. Strict matching is used for fmtb. |
datb | Second datetime value string. |
span | Optional CENTSPAN value; the default is -50. Refer to Using CENTSPAN. |
errctl | Optional error control string. Refer to Datetime error handling. |
%dif | Set to the number of days obtained from subtracting datb from data. If an error is detected, the value returned is 99999999 . |
Example
The following fragment prints the string -7 days
:
Print $sir_datedif('YYMMDD', '970301', , '970308') and 'days'
Error conditions
$Sir_DateDif returns the value 99999999 in the following error cases:
- fmta or fmtb is not a valid datetime format.
- data or datb does not match the respective datetime format.
- data or datb is outside of range permitted for the respective datetime format.
- span is invalid.
For more information about error handling, see the APPDATE command and see Sir_Date_Err.
Usage notes
- Time is ignored in the subtraction.
- In the example above, even though the input dates have 2-digit years, the correct answer would be given for any valid span argument, since the dates do not span the end of February.
- As in the standard SOUL $DateDif function, the single span argument is used for both dates. If it is necessary to get the difference between two dates that both have 2-digit years and are in different 100-year windows, you must first use $Sir_DateCnv to convert one of them to some 4-digit year format. Alternatively, you could use $Sir_Date2ND to convert both dates to number of days values, and subtract those values.