$DateDif: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Mlarocca moved page $DATEDIF to $DateDif: Lower case change)
 
(3 intermediate revisions by 2 users not shown)
Line 4: Line 4:
==Syntax==
==Syntax==
<p>
<p>
The format of the <var>$Datedif</var> function is:</p>
The format of the <var>$DateDif</var> function is:</p>
<p class="syntax">$Datedif(<span class="term">date-1-format</span>, <span class="term">date-1</span>, <span class="term">date-2-format</span>, <span class="term">date-2</span>, <span class="term">defcent</span>, <span class="term">centsplt</span>)</p>
<p class="syntax">$DateDif(<span class="term">date-1-format</span>, <span class="term">date-1</span>, <span class="term">date-2-format</span>, <span class="term">date-2</span>, [<span class="term">defcent</span>], [<span class="term">centsplt</span>])</p>
<p>
<p>
Where:</p>
Where:</p>
<ul>
<ul>
<li><var class="term">date-1-format</var> specifies the format of the first date. The format can be a combination of these elements:   
<li><var class="term">date-1-format</var> specifies the format of the first date. The format can be a combination of these elements:   
<table>
<table class="thJustBold">
<tr>
<tr>
<td>DD</td>
<th>DD</th>
<td>Gregorian numeric day</td>
<td>Gregorian numeric day</td>
</tr>
</tr>


<tr>
<tr>
<td>DDD</td>
<th>DDD</th>
<td>Julian numeric date</td>
<td>Julian numeric date</td>
</tr>
</tr>


<tr>
<tr>
<td>MM</td>
<th>MM</th>
<td>Numeric month</td>
<td>Numeric month</td>
</tr>
</tr>


<tr>
<tr>
<td>MON</td>
<th>MON</th>
<td>Abbreviated month name</td>
<td>Abbreviated month name</td>
</tr>
</tr>


<tr>
<tr>
<td>MONTH</td>
<th>MONTH</th>
<td>Full month name</td>
<td>Full month name</td>
</tr>
</tr>


<tr>
<tr>
<td>YY</td>
<th>YY</th>
<td>Last two digits of numeric year (assumes that the year prefix is 19)</td>
<td>Last two digits of numeric year (assumes that the year prefix is 19)</td>
</tr>
</tr>


<tr>
<tr>
<td>YYYY</td>
<th>YYYY</th>
<td>Full numeric year </td>
<td>Full numeric year </td>
</tr>
</tr>


<tr>
<tr>
<td>CYY</td>
<th>CYY</th>
<td>The century, plus the year. Century (C) is a single digit, where 0 represents 1900, 1 represents 2000, and so on.</td>
<td>The century, plus the year. Century (<var>C</var>) is a single digit, where 0 represents 1900, 1 represents 2000, and so on.</td></tr>
</tr>
</table>
</table>
<p>
<p>
Line 55: Line 54:
<ul>
<ul>
<li>A format that has a month, day, and year element</li>
<li>A format that has a month, day, and year element</li>
<li>A Julian date format that has a year element and a day element in the format DDD </li>
<li>A Julian date format that has a year element and a day element in the format <var>DDD</var> </li>
</ul>
</ul>
<p>
<p>
Line 65: Line 64:


<li><var class="term">date-2-format</var> specifies the format of the second date. The format requirements are the same as those for the <var class="term">date-1-format</var> argument. This argument can be omitted but the comma after it is required. If this argument is omitted, <var>$Datedif</var> assumes that <var class="term">date-2</var> is in the same format as <var class="term">date-1</var>. </li>
<li><var class="term">date-2-format</var> specifies the format of the second date. The format requirements are the same as those for the <var class="term">date-1-format</var> argument. This argument can be omitted but the comma after it is required. If this argument is omitted, <var>$Datedif</var> assumes that <var class="term">date-2</var> is in the same format as <var class="term">date-1</var>. </li>
</li>


<li><var class="term">date-2</var> specifies the second date. The date must be either in the format specified in the <var class="term">date-2-format</var> argument, or in the format specified in <var class="term">date-1-format</var> if <var class="term">date-2-format</var> is not specified. The date can be as many as 36 characters in length.</li>
<li><var class="term">date-2</var> specifies the second date. The date must be either in the format specified in the <var class="term">date-2-format</var> argument, or in the format specified in <var class="term">date-1-format</var> if <var class="term">date-2-format</var> is not specified. The date can be as many as 36 characters in length.</li>
</li>


<li>The <var class="term">defcent</var> argument (optional) specifies the <var>[[DEFCENT parameter|DEFCENT]]</var> value to use; it overrides all other <var>DEFCENT</var> and <var>[[CENTSPLT parameter|CENTSPLT]]</var> parameter values. This argument cannot be specified with the <var class="term">centsplt</var> argument, unless one of the values is NULL.</li>
<li>The <var class="term">defcent</var> argument (optional) specifies the <var>[[DEFCENT parameter|DEFCENT]]</var> value to use; it overrides all other <var>DEFCENT</var> and <var>[[CENTSPLT parameter|CENTSPLT]]</var> parameter values. This argument cannot be specified with the <var class="term">centsplt</var> argument, unless one of the values is NULL.</li>
</li>


<li>The <var class="term">centsplt</var> argument (optional) specifies the CENTSPLIT value to use; it overrides all other <var>DEFCENT</var> and <var>CENTSPLT</var> parameter values. This argument cannot be specified with the <var class="term">defcent</var> argument, unless one of the values is NULL.</li>
<li>The <var class="term">centsplt</var> argument (optional) specifies the <var>CENTSPLT</var> value to use; it overrides all other <var>DEFCENT</var> and <var>CENTSPLT</var> parameter values. This argument cannot be specified with the <var class="term">defcent</var> argument, unless one of the values is NULL.</li>
</ul>
</ul>


Line 81: Line 77:
In the following procedure, <code>Date_Difference</code>, <var>$Datedif</var> calculates the difference between dates twice. Before the first <var>Print</var> statement, the <var>[[CUSTOM parameter|CUSTOM]]</var> parameter is set to 1, so the century defaults to the current century. Before the second <var>Print</var> statement, the <var>DEFCENT</var> parameter is set to 20. </p>
In the following procedure, <code>Date_Difference</code>, <var>$Datedif</var> calculates the difference between dates twice. Before the first <var>Print</var> statement, the <var>[[CUSTOM parameter|CUSTOM]]</var> parameter is set to 1, so the century defaults to the current century. Before the second <var>Print</var> statement, the <var>DEFCENT</var> parameter is set to 20. </p>
<p class="code">PROCEDURE DATE_DIFFERENCE
<p class="code">PROCEDURE DATE_DIFFERENCE
RESET CUSTOM=(1)
RESET CUSTOM=1
Begin
Begin
Print $Datedif('CYYDDD','96333','YY MM DD','97 06 22',%defcent,%centsplt)       
Print $Datedif('CYYDDD','96333','YY MM DD','97 06 22',%defcent,%centsplt)       
Line 92: Line 88:
====Separators and leading zeros====
====Separators and leading zeros====
<ul>
<ul>
<li>The separators in each format must match the separators in the corresponding date. For example:</li>
<li>The separators in each format must match the separators in the corresponding date. For example:
<p class="code">$datedif('MON DD, YYYY','JAN 08, 1990','YY:DDD', '88:210')           
<p class="code">$datedif('MON DD, YYYY','JAN 08, 1990','YY:DDD', '88:210')           
</p></li>
</p></li>


<li>When necessary, pad the month or date in the date argument with leading zeros to match the length of corresponding format argument. For example:</li>
<li>When necessary, pad the month or date in the date argument with leading zeros to match the length of corresponding format argument. For example:
<p class="code">$datedif('YY DDD','90 034',,'90 007')   
<p class="code">$datedif('YY DDD','90 034',,'90 007')   
</p></li>
</p></li>
</ul>
</ul>


====How $Datedif works====
====How $DateDif works====
<ul>
<ul>
<li>If date1 is the same as date2, 0 is returned.</li>
<li>If <var class="term">date1</var> is the same as <var class="term">date21</var>, 0 is returned.</li>
</li>
 
<li>If date1 is earlier than date2, a negative integer is returned.</li>
<li>If <var class="term">date1</var> is earlier than <var class="term">date2</var>, a negative integer is returned.</li>
</li>
 
<li>If date1 is later than date2, a positive integer is returned.</li>
<li>If <var class="term">date1</var> is later than <var class="term">date2</var>, a positive integer is returned.</li>
</li>
 
<li>If an error occurs, 999999999 is returned. </li>
<li>If an error occurs, <code>99999999</code> is returned. </li>
</li>
</ul>
</ul>


Line 119: Line 114:
<p>
<p>
prints this value:</p>
prints this value:</p>
<p class="code"><b></b>-456   
<p class="output">-456   
</p>
</p>


[[Category:SOUL $functions]]
[[Category:SOUL $functions]]

Latest revision as of 20:59, 19 October 2018

The $Datedif function returns the difference in days between two dates.

Syntax

The format of the $DateDif function is:

$DateDif(date-1-format, date-1, date-2-format, date-2, [defcent], [centsplt])

Where:

  • date-1-format specifies the format of the first date. The format can be a combination of these elements:
    DD Gregorian numeric day
    DDD Julian numeric date
    MM Numeric month
    MON Abbreviated month name
    MONTH Full month name
    YY Last two digits of numeric year (assumes that the year prefix is 19)
    YYYY Full numeric year
    CYY The century, plus the year. Century (C) is a single digit, where 0 represents 1900, 1 represents 2000, and so on.

    Valid formats are:

    • A format that has a month, day, and year element
    • A Julian date format that has a year element and a day element in the format DDD

    Any EBCDIC characters except single quotes are allowed within the input format and appear unchanged in the output date. The input format can be as many as 32 characters in length.

  • date-1 specifies the first date in the format specified by the date-1-format argument. The date can be as many as 36 characters in length.
  • date-2-format specifies the format of the second date. The format requirements are the same as those for the date-1-format argument. This argument can be omitted but the comma after it is required. If this argument is omitted, $Datedif assumes that date-2 is in the same format as date-1.
  • date-2 specifies the second date. The date must be either in the format specified in the date-2-format argument, or in the format specified in date-1-format if date-2-format is not specified. The date can be as many as 36 characters in length.
  • The defcent argument (optional) specifies the DEFCENT value to use; it overrides all other DEFCENT and CENTSPLT parameter values. This argument cannot be specified with the centsplt argument, unless one of the values is NULL.
  • The centsplt argument (optional) specifies the CENTSPLT value to use; it overrides all other DEFCENT and CENTSPLT parameter values. This argument cannot be specified with the defcent argument, unless one of the values is NULL.

Usage

Dates in differing centuries

In the following procedure, Date_Difference, $Datedif calculates the difference between dates twice. Before the first Print statement, the CUSTOM parameter is set to 1, so the century defaults to the current century. Before the second Print statement, the DEFCENT parameter is set to 20.

PROCEDURE DATE_DIFFERENCE RESET CUSTOM=1 Begin Print $Datedif('CYYDDD','96333','YY MM DD','97 06 22',%defcent,%centsplt) %defcent = 20 Print $Datedif('CYYDDD','096333','YY MM DD','97 06 22',%defcent,%centsplt) End END PROCEDURE

Separators and leading zeros

  • The separators in each format must match the separators in the corresponding date. For example:

    $datedif('MON DD, YYYY','JAN 08, 1990','YY:DDD', '88:210')

  • When necessary, pad the month or date in the date argument with leading zeros to match the length of corresponding format argument. For example:

    $datedif('YY DDD','90 034',,'90 007')

How $DateDif works

  • If date1 is the same as date21, 0 is returned.
  • If date1 is earlier than date2, a negative integer is returned.
  • If date1 is later than date2, a positive integer is returned.
  • If an error occurs, 99999999 is returned.

Example

The following statement:

Print $datedif('MMDDYY','010790',,'040891')

prints this value:

-456