$DateCnv: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (minor cleanup)
m (add link)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<p>
<p>
The $DATECNV function converts an input date from its current format to a format you specify and, also, determines whether the input date is valid. If a format error occurs or the input date is not valid, the function returns all asterisks (*). $DATECNV supports both a 2- and a 4-digit year format; the year prefix can come from one of four places.</p>
The <var>$DateCnv</var> function converts an input date from its current format to a format you specify and, also, determines whether the input date is valid. If a format error occurs or the input date is not valid, the function returns all asterisks (*). <var>$$DateCnv</var> supports both a 2- and a 4-digit year format; the year prefix can come from one of four places.</p>


===Syntax===
==Syntax==
<p>
<p>
The format of the $DATECNV function is:</p>
The format of the <var>$DateCnv</var> function is:</p>
<p class="syntax">$DATECNV(<span class="term">input format</span>, <span class="term">output format</span>, <span class="term">input date</span>, <span class="term">defcent</span>, <span class="term">centsplt</span>)  
<p class="syntax">$DateCnv(<span class="term">input-format</span>, <span class="term">output-format</span>, <span class="term">input-date</span>, [<span class="term">defcent</span>], [<span class="term">centsplt</span>])  
</p>
</p>
<p>
<p>
Where:</p>
Where:</p>
<ul>
<ul>
<li><var class="term">input format</var> specifies the format of the input date. The format can be a combination of these elements:
<li><var class="term">input-format</var> specifies the format of the input 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>
Valid formats are:</p>
Valid formats are:</p>
<p>A format that has a month, day, and year element</p>
<p>A format that has a month, day, and year element.</p>
<p>A Julian date format that has a year element and a day element in the format DDD </p>
<p>A Julian date format that has a year element and a day element in the format <var>DDD</var>. </p>
<p>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. </p>
<p>
<p>When you use a 2-digit year, for example, YY is 98) in the input format and a 4-digit year (YYYY) in the output format, <var class="product">Model&nbsp;204</var> assumes that the century is 19-, for example, 1998.</p>
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. </p>
<p>
When you use a 2-digit year, for example, <var>YY</var> is 98) in the input format and a 4-digit year (<var>YYYY</var>) in the output format, <var class="product">Model&nbsp;204</var> assumes that the century is 19-, for example, 1998.</p>


<li><var class="term">output format</var> specifies the format of the output date. The format requirements are the same as those for the input format argument. Using a 2-digit year (YY) in the output format leaves you with no way to distinguish between centuries. For example:
<li><var class="term">output-format</var> specifies the format of the output date. The format requirements are the same as those for the <var class="term">input-format</var> argument. Using a 2-digit year (<var>YY</var>) in the output format leaves you with no way to distinguish between centuries. For example:
<p class="code">$DATECNV('MON DD, YYYY', 'YY DDD', 'JAN 10, 2005')
<p class="code">$DateCnv('MON DD, YYYY', 'YY DDD', 'JAN 10, 2005')
</p>
</p>
<p>
<p>
produces the following output:</p>
produces the following output:</p>
<p class="code">05 010
<p class="output">05 010
</p>
</p>
<p>
<p>
However, the output is exactly the same if the input date is January 10, 1905 or January 10, 2105.</p>
However, the output is exactly the same if the input date is <code>January 10, 1905</code> or <code>January 10, 2105</code>.</p>
</li>
</li>


<li><var class="term">input date</var> specifies the input date in the format indicated by the input format argument. The input date can be as many as 36 characters in length.</li>
<li><var class="term">input-date</var> specifies the input date in the format indicated by the <var class="term">input-format</var> argument. The input date can be as many as 36 characters in length.</li>
 
<li><var class="term">defcent</var> (optional) specifies the <var>[[DEFCENT parameter|DEFCENT]]</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">centsplt</var> argument, unless one of the values is NULL. </li>
 
<li><var class="term">centsplt</var> (optional) specifies the <var>[[CENTSPLT parameter|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 defcent argument, unless one of the values is NULL. </li>
</ul>


<li><var class="term">defcent</var> (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. </li>
===Separators and leading zeros===
<p>
Use separators and leading zeros as specified here:</p>
<ul>
<li>Separators in the <var class="term">input-format</var> argument must match the separators in the <var class="term">input-date</var> argument. For example:
<p class="code">$DateCnv('MONTH - DD - YYYY','MON DD, YYYY', 'JANUARY - 05 - 1990')
</p></li>


<li><var class="term">centsplt</var> (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. </li>
<li>When necessary, you must pad the month or date in the input date argument with leading zeros to match the length of <var class="term">input-format</var>. For example:
<p class="code">$DateCnv('YY DDD','MON DD, YYYY','90 023')  
</p></li>
</ul>
</ul>
==Examples==
In addition to the following examples, see also [[Overview of $Date functions#Examples|these examples]].
<ol>
<li><p class="code">Print $DateCnv('DDMMYY','MON DD, YYYY','010790')
</p>
<p>
<p>
The following example shows the use of the $DATECNV converting dates in various centuries.</p>
prints this value:</p>
<p class="output">JUL 01, 1990 
</p></li>
 
<li><p>
The following example shows <var>$DateCnv</var> converting dates in various centuries.</p>
<p class="code">PROCEDURE CENTSPLT
<p class="code">PROCEDURE CENTSPLT
BEGIN
BEGIN
Line 101: Line 127:
END
END
END PROCEDURE
END PROCEDURE
</p>
</p> </li>
<p>
</ol>
For an explanation of the DEFCENT and CENTSPLT parameters processing see Rocket <var class="product">Model&nbsp;204</var> Parameter and Command Reference Manual in the chapter on parameters.</p>
===Separators and leading zeros===
<p>
Use separators and leading zeros as specified here:</p>
<ul>
<li>Separators in the input format argument must match the separators in the input date argument. For example:</li>
<p class="code">$DATECNV('MONTH - DD - YYYY','MON DD, YYYY', -
      'JANUARY - 05 - 1990')
</p></li>
 
<li>When necessary, you must pad the month or date in the input date argument with leading zeros to match the length of input format. For example:</li>
<p class="code">$DATECNV('YY DDD','MON DD, YYYY','90 023')
</p></li>
</ul>
 
===Example===
<p class="code">PRINT $DATECNV('DDMMYY','MON DD, YYYY','010790')
</p>
<p>
prints this value:</p>
<p class="code">JUL 01, 1990 
</p>


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

Latest revision as of 21:24, 6 October 2015

The $DateCnv function converts an input date from its current format to a format you specify and, also, determines whether the input date is valid. If a format error occurs or the input date is not valid, the function returns all asterisks (*). $$DateCnv supports both a 2- and a 4-digit year format; the year prefix can come from one of four places.

Syntax

The format of the $DateCnv function is:

$DateCnv(input-format, output-format, input-date, [defcent], [centsplt])

Where:

  • input-format specifies the format of the input 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.

    When you use a 2-digit year, for example, YY is 98) in the input format and a 4-digit year (YYYY) in the output format, Model 204 assumes that the century is 19-, for example, 1998.

  • output-format specifies the format of the output date. The format requirements are the same as those for the input-format argument. Using a 2-digit year (YY) in the output format leaves you with no way to distinguish between centuries. For example:

    $DateCnv('MON DD, YYYY', 'YY DDD', 'JAN 10, 2005')

    produces the following output:

    05 010

    However, the output is exactly the same if the input date is January 10, 1905 or January 10, 2105.

  • input-date specifies the input date in the format indicated by the input-format argument. The input date can be as many as 36 characters in length.
  • defcent (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.
  • centsplt (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.

Separators and leading zeros

Use separators and leading zeros as specified here:

  • Separators in the input-format argument must match the separators in the input-date argument. For example:

    $DateCnv('MONTH - DD - YYYY','MON DD, YYYY', 'JANUARY - 05 - 1990')

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

    $DateCnv('YY DDD','MON DD, YYYY','90 023')

Examples

In addition to the following examples, see also these examples.

  1. Print $DateCnv('DDMMYY','MON DD, YYYY','010790')

    prints this value:

    JUL 01, 1990

  2. The following example shows $DateCnv converting dates in various centuries.

    PROCEDURE CENTSPLT BEGIN %INPUT_FORMAT = 'YYDDD' %OUTPUT_FORMAT = 'YYYY MM DD' %INPUT_VALUE = '9633' %CENTSPLT = 97 %DEFCENT = ' ' CALL PIT %CENTSPLT = ' ' %DEFCENT = 19 CALL PIT %INPUT_FORMAT = 'YYYYDDD' %INPUT_VALUE = '2006333' CALL PIT PIT: SUBROUTINE PRINT %INPUT_FORMAT ' ' %OUTPUT_FORMAT ' ' %INPUT_VALUE - ' ' %DEFCENT ' ' %CENTSPLT PRINT $DATECNV(%INPUT_FORMAT, %OUTPUT_FORMAT,%INPUT_VALUE, - %DEFCENT, %CENTSPLT) RETURN END SUBROUTINE END END PROCEDURE