$Sir DateDif: Difference between revisions
m (change link for CENTSPAN) |
m (change link forCENTSPAN) |
||
Line 7: | Line 7: | ||
and two datetime value strings. | and two datetime value strings. | ||
It accepts a second optional datetime format string, an optional | It accepts a second optional datetime format string, an optional | ||
<var>[[ | <var>[[Sir2000 datetime processing considerations#Processing dates with two-digit year values|CENTSPAN]]</var> value, and an optional error control string. </p> | ||
<p> | <p> | ||
<var>$Sir_DateDif</var> subtracts the second datetime value from the first | <var>$Sir_DateDif</var> subtracts the second datetime value from the first | ||
Line 34: | Line 34: | ||
<tr><th>span</th> | <tr><th>span</th> | ||
<td>Optional <var> | <td>Optional <var>[[Sir2000 datetime processing considerations#Processing dates with two-digit year values|CENTSPAN]]</var> value; the default is -50. </td></tr> | ||
<tr><th>errctl</th> | <tr><th>errctl</th> | ||
Line 76: | Line 76: | ||
dates that both have 2-digit years and are in different 100-year | dates that both have 2-digit years and are in different 100-year | ||
windows, you must first use <var>[[$Sir_DateCnv]]</var> to convert one of them to some 4-digit year format. | windows, you must first use <var>[[$Sir_DateCnv]]</var> to convert one of them to some 4-digit year format. | ||
Alternatively, you could use <var>[[$Sir_Date2ND]]</var> to convert both dates to number of days values, and subtract those values.</li> | <p> | ||
Alternatively, you could use <var>[[$Sir_Date2ND]]</var> to convert both dates to number of days values, and subtract those values. </p></li> | |||
</ul> | </ul> | ||
[[Category:Sir2000 User Language Tools $functions]] | [[Category:Sir2000 User Language Tools $functions]] |
Revision as of 21:49, 8 February 2018
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:
%dif | Set to the number of days obtained from subtracting datb from data. If an error is detected, the value returned is 99999999 . |
---|---|
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. |
errctl | Optional error control string. Refer to Error handling control with DATE_ERR. |
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 Errors in datetime $functions.
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.