$Sir_DateChk

From m204wiki
Revision as of 17:11, 23 September 2015 by JAL (talk | contribs) (Created page with "{{DISPLAYTITLE:$Sir_DateChk}} <span class="pageSubtitle">Check if datetime matches format</span> <p class="warn"><b>Note:</b> This $function require the <var class="product">...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Check if datetime matches format

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

The $Sir_DateChk function expects a datetime format string and a datetime value string. It accepts an optional CENTSPAN value, and an optional error control string. $Sir_DateChk returns the value 1 if the datetime value is valid and matches the provided format, otherwise the value 0 is returned.

The $Sir_DateChk function is similar to the $DATECHK standard SOUL function. However, the $DateChk function does not support the specification of a CENTSPLT or DEFCENT argument.

Syntax

%tst = $Sir_DateChk(fmt, dat, span, errctl)

Where:

fmt Datetime format string. Refer to Datetime string formats for an explanation of valid datetime formats and valid dates. Strict matching is used for fmt.
dat Datetime string.
span Optional CENTSPAN value, default is -50. Refer to Using CENTSPAN.
errctl Optional error control string, refer to Datetime error handling.
%tst Set to 1 if dat matches fmt; otherwise set to 0.

The following fragment prints the string Bad, since February cannot have thirty days. Note that the request is not cancelled, even though an optional error control string was provided:

%x = $sir_datechk('DAY Month, YYYY', - '30 February, 1997',,'CANCEL') if %x = 1 then print 'Good' else print 'Bad' end if

Error conditions

$Sir_DateChk returns a value of 0 if any of the following errors are detected:

  • fmt is not a valid datetime format.
  • dat is not a valid date, or does not match fmt, or is outside of range permitted for fmt. Note that these cases are always treated as if an error control string of IGNORE had been specified.
  • span is not a valid CENTSPAN value.

For more information about error handling, see the APPDATE command and see Sir_Date_Err.