$Sir DateCnv: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:$Sir_DateCnv}} <span class="pageSubtitle">Convert datetime to different format</span> <p class="warn"><b>Note:</b> This $function require the <var class="produ...")
 
m (link repair)
 
(6 intermediate revisions by the same user not shown)
Line 2: Line 2:
<span class="pageSubtitle">Convert datetime to different format</span>
<span class="pageSubtitle">Convert datetime to different format</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>
<p>
The <var>$Sir_DateCnv</var> function expects a datetime format string for the
The <var>$Sir_DateCnv</var> function expects a datetime format string for the
input string, a datetime format for the output string, and a datetime
input string, a datetime format for the output string, and a datetime
value to be converted.
value to be converted.
It also accepts an optional <var>CENTSPAN</var> value and an optional
It also accepts an optional <var>[[Datetime string formats#Using CENTSPAN|CENTSPAN]]</var> value and an optional error control string.</p>
error control string.</p>
<p>
<p>
<var>$Sir_DateCnv</var> returns the input datetime converted to the output format.</p>
<var>$Sir_DateCnv</var> returns the input datetime converted to the output format.</p>


==Syntax==
==Syntax==
<p class="syntax"><span class="term">%odat</span> = $Sir_DateCnv(<span class="term">infmt, outfmt, dat, span, errctl</span>)
<p class="syntax"><span class="term">%odat</span> = $Sir_DateCnv(<span class="term">infmt</span>, <span class="term">outfmt</span>, <span class="term">dat</span>, [<span class="term">span</span>], [<span class="term">errctl</span>])
</p>
</p>
Where:
Where:
<table>
<table>
<tr><th>%odat</th>
<td>Set to the value of <var class="term">dat</var>, converted from the format in <var class="term">infmt</var> to the format in <var class="term">outfmt</var>, unless an error is detected.</td></tr>
<tr><th>infmt</th>
<tr><th>infmt</th>
<td>Datetime format string for <var class="term">dat</var>. Refer to [[Datetime string formats]] for an explanation of valid datetime formats and valid dates. Strict matching is used for <var class="term">infmt</var>.</td></tr>
<td>Datetime format string for <var class="term">dat</var>. Refer to [[Datetime string formats]] for an explanation of valid datetime formats and valid dates. [[Datetime string formats#Strict and non-strict format matching|Strict matching]] is used for <var class="term">infmt</var>.</td></tr>


<tr><th>outfmt</th>
<tr><th>outfmt</th>
Line 30: Line 32:


<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>%odat</th>
<td>Set to the value of <var class="term">dat</var>, converted from the format in <var class="term">infmt</var> to the format in <var class="term">outfmt</var>, unless an error is detected.</td></tr>
</table>
</table>


Line 60: Line 59:


<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>


[[Category:$Functions|$Sir_DateCnv]]
[[Category:Sir2000 User Language Tools $functions]]
[[Category:Sir2000 User Language Tools $functions]]

Latest revision as of 22:53, 8 February 2018

Convert datetime to different format

Note: This $function require the Sir2000 User Language Tools product.

The $Sir_DateCnv function expects a datetime format string for the input string, a datetime format for the output string, and a datetime value to be converted. It also accepts an optional CENTSPAN value and an optional error control string.

$Sir_DateCnv returns the input datetime converted to the output format.

Syntax

%odat = $Sir_DateCnv(infmt, outfmt, dat, [span], [errctl])

Where:

%odat Set to the value of dat, converted from the format in infmt to the format in outfmt, unless an error is detected.
infmt Datetime format string for dat. Refer to Datetime string formats for an explanation of valid datetime formats and valid dates. Strict matching is used for infmt.
outfmt Datetime format string for function output (%odat).
dat Input datetime string.
span Optional CENTSPAN value, default is -50. Refer to Using CENTSPAN.
errctl Optional error control string, refer to Error handling control with DATE_ERR.

Example

The following fragment prints the string 19970101:

Print $sir_datecnv('YYMMDD', 'YYYYMMDD', '970101', 1950)

Error conditions

$Sir_DateCnv returns a string composed of all asterisks (*), whose length is the shorter of the length of the output date format string or 32, in the following error cases:

  • infmt or outfmt is not a valid datetime format string.
  • dat does not match infmt.
  • dat is outside of range permitted for infmt or that permitted for outfmt.
  • span is invalid.

For more information about error handling, see Errors in datetime $functions.