$Sir DateDif: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (test modify category)
m (link repair)
 
(11 intermediate revisions by the same user not shown)
Line 2: Line 2:
<span class="pageSubtitle">Difference between two dates</span>
<span class="pageSubtitle">Difference between two dates</span>


<p class="warn"><b>Note:</b> This $function require the <var class="product">[[Media:Ul2krNew.pdf|Sir2000 User Language Tools]]</var> product. </p>  
<p class="warn"><b>Note:</b> This $function require the <var class="product">[[Sir2000 User Language Tools]]</var> product. </p>  


<p>The <var>$Sir_DateDif</var> function expects a datetime format string
<p>The <var>$Sir_DateDif</var> function expects a datetime format string
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>[[Datetime string formats#Using CENTSPAN|CENTSPAN]]</var> value, and an optional error control string. </p>
<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 14: Line 14:


===Syntax===
===Syntax===
<p class="syntax"><span class="term">%dif</span> = $Sir_DateDif(<span class="term">fmta</span>, <span class="term">data</span>, <span class="term">fmtb</span>, <span class="term">datb</span>, [<span class="term">span</span>], [<span class="term">errctl</span>])
<p class="syntax"><span class="term">%dif</span> = $Sir_DateDif(<span class="term">fmta</span>, <span class="term">data</span>, [<span class="term">fmtb</span>], <span class="term">datb</span>, [<span class="term">span</span>], [<span class="term">errctl</span>])
</p>
</p>
Where:
Where:
<table>
<table>
<tr><th>%dif</th>
<td>Set to the number of days obtained from subtracting <var class="term">datb</var> from <var class="term">data</var>. If an error is detected, the value returned is <code>99999999</code>.</td></tr>
<tr><th>fmta</th>
<tr><th>fmta</th>
<td>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 <var class="term">fmta</var>.</td></tr>
<td>First datetime format string. Refer to [[Datetime string formats]] for an explanation of valid datetime formats and valid datetime values. [[Datetime string formats#Strict and non-strict format matching|Strict matching]] is used for <var class="term">fmta</var>.</td></tr>


<tr><th>data</th>
<tr><th>data</th>
Line 31: Line 34:


<tr><th>span</th>
<tr><th>span</th>
<td>Optional <var>CENTSPAN</var> value; the default is -50. Refer to [[Datetime string formats#Using CENTSPAN|Using CENTSPAN]].</td></tr>
<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>
<td>Optional error control string. Refer to [[Datetime string formats#Datetime error handling|Datetime error handling]].</td></tr>
<td>Optional error control string. Refer to [[The Sir2000 APPDATE command#Error handling control with DATE ERR|Error handling control with DATE_ERR]].</td></tr>
 
<tr><th>%dif</th>
<td>Set to the number of days obtained from subtracting <var class="term">datb</var> from <var class="term">data</var>. If an error is detected, the value returned is <code>99999999</code>.</td></tr>
</table>
</table>


Line 60: Line 60:


<p>
<p>
For more information about error handling, see the <var>[[APPDATE command|APPDATE]]</var> command
For more information about error handling, see [[Sir2000 User Language Tools $functions#Errors in datetime $functions|Errors in datetime $functions]]. </p>
and see <var>[[Sir_Date_Err]]</var>. </p>


===Usage notes===
===Usage notes===
Line 77: 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:$Functions|$Sir_DateDif]]
[[Category:Sir2000 User Language Tools $functions]]
[[Category:Sir2000 User Language Tools $functions]]

Latest revision as of 22:55, 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.