$DateCnv: Difference between revisions
m (misc cleanup) |
|||
Line 1: | Line 1: | ||
<p> | <p> | ||
The <var>$ | 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 <var>$ | The format of the <var>$DateCnv</var> function is:</p> | ||
<p class="syntax">$ | <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 class="thJustBold"> | <table class="thJustBold"> | ||
<tr> | <tr> | ||
Line 49: | Line 49: | ||
<tr> | <tr> | ||
<th>CYY</th> | <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> | ||
Line 61: | Line 61: | ||
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 204</var> assumes that the century is 19-, for example, 1998.</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 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 (<var>YY</var>) 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">$ | <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=" | <p class="output">05 010 | ||
</p> | </p> | ||
<p> | <p> | ||
Line 72: | Line 72: | ||
</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">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> | ||
Line 83: | Line 83: | ||
Use separators and leading zeros as specified here:</p> | Use separators and leading zeros as specified here:</p> | ||
<ul> | <ul> | ||
<li>Separators in the input format argument must match the separators in the input date argument. For example: | <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">$ | <p class="code">$DateCnv('MONTH - DD - YYYY','MON DD, YYYY', 'JANUARY - 05 - 1990') | ||
</p></li> | </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>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">$ | <p class="code">$DateCnv('YY DDD','MON DD, YYYY','90 023') | ||
</p></li> | </p></li> | ||
</ul> | </ul> | ||
Line 94: | Line 94: | ||
==Examples== | ==Examples== | ||
<ol> | <ol> | ||
<li><p class="code"> | <li><p class="code">Print $DateCnv('DDMMYY','MON DD, YYYY','010790') | ||
</p> | </p> | ||
<p> | <p> | ||
prints this value:</p> | prints this value:</p> | ||
<p class=" | <p class="output">JUL 01, 1990 | ||
</p></li> | </p></li> | ||
<li><p> | <li><p> | ||
The following example shows <var>$ | 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 |
Revision as of 22:07, 23 September 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
orJanuary 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
Print $DateCnv('DDMMYY','MON DD, YYYY','010790')
prints this value:
JUL 01, 1990
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