Datetime string formats: Difference between revisions
m (add category) |
|||
(41 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
The discussion of datetime processing on this page applies to $functions, #functions, and commands added to the Rocket M204 products in version 7.5 of Model 204. These added functions and commands share "datetime formats" that differ from those in the pre-7.5 standard Model 204 related date $functions. | |||
The | |||
Although the discussion here tends to emphasize the SOUL [[SOUL_$functions#datetime|$Sir_Date<i>xxx</i> $functions]], these datetime format strings are used in several Rocket Model 204 add-on products, including: | |||
$functions. | |||
<ul> | <ul> | ||
<li> | <li><var class="product">[[Fast/Unload datetime processing considerations|Fast/Unload]]</var> </li> | ||
" | |||
<li><var class="product">[[Media:JoclrNew.pdf|Janus Open Client]]</var> </li> | |||
< | |||
<li> | <li><var class="product">[[Media:JosrvrNew.pdf|Janus Open Server]]</var> | ||
</li> | |||
<li> | |||
<li><var class="product">[[Media:JsdsrNew.pdf|Janus Specialty Data Store]]</var> </li> | |||
< | |||
<li> | <li><var class="product">[[Janus Web Server]]</var> </li> | ||
<li> | |||
< | <li><var class="product">[[SirDBA]]</var> </li> | ||
< | |||
<li> | |||
<li> | |||
< | |||
</ | |||
<li> | |||
<li> | |||
<li> | |||
<li> | |||
<li> | |||
<li><var class="product">[[Media:SirfieldNew.pdf|Sir2000 Field Migration Facility]]</var> | |||
<li><var class="product">[[Sir2000 User Language Tools]]</var> </li> | |||
</ul> | |||
<br> | |||
< | |||
==Datetime formats== | |||
The string representation of a date is described by a '''datetime format'''. | |||
This value is a character string, composed of the concatenation of these: | |||
<ul> | <ul> | ||
<li> | <li>Tokens | ||
< | <p> | ||
< | For example, <var>YYYY</var> for a four-digit year, and <var>MI</var> for | ||
minutes.</p></li> | |||
< | |||
< | <li>Separator characters | ||
< | <p> | ||
<li> | For example, forward slash (<tt>/</tt>) in <var>MM/DD/YY</var> for two-digit month, day, and year separated by slashes.</p></li> | ||
<li> | |||
< | |||
< | |||
< | |||
< | |||
< | |||
< | |||
<li> | |||
</ul> | </ul> | ||
These datetime format strings are used in many methods, commands, and | |||
$functions. Since all methods that operate on strings are functions, methods and $functions are collectively referred to as ''functions'' on this page. | |||
The rules for these datetime format strings are consistent | |||
wherever these formats are used, though certain uses of these strings might impose extra restrictions. | |||
For example, a leading blank may match an <var>HH</var>, <var>DD</var>, or <var>MM</var> token in [[Object oriented programming in SOUL|SOUL methods]], | |||
but it may not in some cases in other Rocket M204 products. | |||
{{Template:Datetime rules, tokens, and separators}} | |||
==Valid datetimes== | ==Valid datetimes== | ||
Line 229: | Line 49: | ||
<ul> | <ul> | ||
<li>Its length must be less than 128 characters. | <li>Its length must be less than 128 characters. | ||
<li>It must be compatible with its corresponding format string. | <li>It must be compatible with its corresponding format string. | ||
<li>It must represent a valid date and/or time. | <li>It must represent a valid date and/or time. | ||
<p> | |||
For example, at most 23:59:59.999 for a time, 01-12 for a month, 01-31 | For example, at most 23:59:59.999 for a time, 01-12 for a month, 01-31 | ||
or less (depending on the month) for a day, February 29 is only valid | or less (depending on the month) for a day, February 29 is only valid | ||
in leap years (only centuries divisible by 4 are leap years: 2000 is | in leap years (only centuries divisible by 4 are leap years: 2000 is | ||
but neither 1800, 1900, nor 2100 are). | but neither 1800, 1900, nor 2100 are). </p> | ||
<p> | <p class="note"> | ||
'''Note:''' weekdays are not checked for consistency against the date. | '''Note:''' weekdays are not checked for consistency against the date. | ||
For example, both <code>Saturday, 02/15/97</code> and <code>Friday, 02/15/97</code> are valid. </p> | For example, both <code>Saturday, 02/15/97</code> and <code>Friday, 02/15/97</code> are valid. </p> | ||
<li>It must be within the date range allowed for the corresponding format. | <li>It must be within the date range allowed for the corresponding format. | ||
A datetime string used with a CYY or ZYY format can only represent dates from 1900 to 2899, inclusive. | <p> | ||
A datetime string used with a <var>CYY</var> or <var>ZYY</var> format can only represent dates from 1900 to 2899, inclusive. | |||
Except for <var class="product">SirDBA</var>, a datetime string used with a <var>YY</var> format can only represent | |||
dates in a range of 100 or less years, as determined by <var>[[#Using CENTSPAN|CENTSPAN]]</var> and <var>[[#Using SPANSIZE|SPANSIZE]]</var>. | dates in a range of 100 or less years, as determined by <var>[[#Using CENTSPAN|CENTSPAN]]</var> and <var>[[#Using SPANSIZE|SPANSIZE]]</var>. | ||
The valid range of dates for all other formats is from 1 January 1753 thru 31 December 9999. | The valid range of dates for all other formats is from <code>1 January 1753</code> thru <code>31 December 9999</code>.</p> | ||
</ul> | </ul> | ||
==Processing dates with two-digit year values== | ==Processing dates with two-digit year values== | ||
{{Template:Processing dates with two-digit year values}} | |||
==Strict and non-strict format matching== | ==Strict and non-strict format matching== | ||
As mentioned above in [[#Datetime formats|Datetime formats]], for some of the functions, the input format rule for a token is the same as the output format rule. This is the definition of "strict date format matching." | |||
As mentioned above, for some of the functions, the input format rule for a token is the same as the output format rule | However, non-strict functions sometimes allow a string to match a token on input that would not be produced by that token on output. | ||
However, non-strict functions sometimes allow a string to match a token on input that would not be produced by that token | |||
on output. | |||
The types of strict matching are as follows: | The types of strict matching are as follows: | ||
{{Template:Datetime format matching}} | |||
<p> | |||
The strict functions are only available in the <var class="product">[[Sir2000 User Language Tools]]</var>. With non-strict date $functions, however, you can use the following technique to check a datetime string using strict rules: | |||
< | |||
you | |||
</p> | </p> | ||
<p class="code">If <i>date</i> Eq '' Or <i>date</i> NE $Sir_NM2Date(- | |||
$Sir_Date2NM(<i>date</i>, <i>fmt</i>), <i>fmt</i>) Then | |||
<i>error handling</i> | |||
End If </p> | |||
<p> | |||
Or, using SOUL OO functions: </p> | |||
<p class="code">if <i>date</i> eq '' or | |||
<i>date</i> ne <i>date</i>:[[StringToMilliseconds (String function)|stringToMilliseconds]](<i>format</i>):[[MillisecondsToString (Float function)|millisecondsToString]](<i>format</i>) then | |||
<i>error handling</i> | |||
end if </p> | |||
==Datetime and format examples== | ==Datetime and format examples== | ||
The extensive set of format tokens is shown in [[Datetime string formats#Datetime | The extensive set of format tokens is shown above in [[Datetime string formats#Datetime format tokens|Datetime format tokens]]. | ||
These tokens and the various separator characters can be combined in almost limitless possibility, giving | These tokens and the various separator characters can be combined in almost limitless possibility, giving | ||
rise to an extremely large set of datetime formats. | rise to an extremely large set of datetime formats. | ||
Line 355: | Line 100: | ||
This section provides examples of some common datetime formats, and | This section provides examples of some common datetime formats, and | ||
also tries to explain the use of some of the format tokens that might not be obvious. | also tries to explain the use of some of the format tokens that might not be obvious. | ||
It also has examples for formats whose usage | It also has examples for formats whose usage differs depending on whether [[Datetime string formats#Strict and non-strict format matching|strict or non-strict format matching]] is involved. | ||
Each example format is explained and also presented with some matching datetimes; again, bear in mind that these tokens can be combined in very many ways and only a very few are shown here. | Each example format is explained and also presented with some matching datetimes; again, bear in mind that these tokens can be combined in very many ways and only a very few are shown here. | ||
It is assumed that these examples are invoked sometime between the | It is assumed that these examples are invoked sometime between the | ||
years 1998-2040, as the basis for relative <var>CENTSPAN</var> calculations. | years 1998-2040, as the basis for relative <var>CENTSPAN</var> calculations. | ||
< | <p class="note"><b>Note:</b> For comparable Fast/Unload examples, see [[Fast/Unload datetime processing considerations#Datetime and format examples|Fast/Unload datetime and format examples]]. | ||
</p> | </p> | ||
{{Template:Datetime and format examples}} | |||
==Datetime error handling== | ==Datetime error handling== | ||
Due to an invalid argument value to a datetime | <p class="note"><b>Note:</b> For a comparable Fast/Unload discussion, see [[Fast/Unload datetime processing considerations#Datetime error handling|Fast/Unload datetime error handling]]. </p> | ||
any of the following errors can occur: | |||
Due to an invalid argument value to a datetime function, any of the following errors can occur: | |||
<ul> | <ul> | ||
<li> | <li>Invalid datetime format specification | ||
<li> | <li>Datetime string not matching format | ||
<li> | <li>Datetime out of range for the format | ||
<li> | <li>Invalid <var>CENTSPAN</var> value | ||
<li> | <li>Datetime out of range for <var>CENTSPAN</var>/<var>SPANSIZE</var> combination | ||
</ul> | </ul> | ||
One way to detect these errors is to check for the | One way to detect these errors is to check for the appropriate error return value: | ||
appropriate error return value: | |||
<ol> | <ol> | ||
<li> | <li>Functions using a numeric value to represent a datetime, and | ||
<var>$Sir_Date</var>, have error return values of | <var>$Sir_Date</var>, have error return values of | ||
-9.E12 or a null string for numeric or string result | <code>-9.E12</code> or a null string for numeric or string result functions, respectively. | ||
<li>$Functions (other than <var>$Sir_Date</var>) that only manipulate strings and associated | <li>$Functions (other than <var>$Sir_Date</var>) that only manipulate strings and associated | ||
datetime formats have error return values of a | datetime formats have error return values of a | ||
variable number of asterisks (or, in the case of <var>$Sir_DateDif</var> | variable number of asterisks (or, in the case of <var>$Sir_DateDif</var>, | ||
the value 99,999,999). | the value 99,999,999). | ||
<var>$Sir_DateDif</var> and the date $functions that return a | <var>$Sir_DateDif</var> and the date $functions that return a | ||
variable number of asterisks as error indication | variable number of asterisks as error indication are available only with the <var class="product">[[Sir2000 User Language Tools]]</var>. | ||
are available only with the <var class="product">Sir2000 User Language Tools</var>. | |||
</ol> | </ol> | ||
If you are authorized to use the <var class="product">Sir2000 User Language Tools</var>, you can modify the | If you are authorized to use the <var class="product">Sir2000 User Language Tools</var>, you can modify the error detection algorithm so that warning messages or request cancellation occur when a datetime error occurs. | ||
error detection algorithm so that warning messages or request | |||
cancellation occur when a datetime error occurs. | |||
One significant advantage of this product is that you can add | One significant advantage of this product is that you can add | ||
a great deal of error detection to applications without modifying | a great deal of error detection to applications without modifying | ||
any <var class="product"> | any <var class="product">SOUL</var> code. | ||
Also, for case 2, above, thorough error detection of error | Also, for case 2, above, thorough error detection of error return values is somewhat complex. | ||
return values is somewhat complex. | |||
With the <var class="product">Sir2000 User Language Tools</var>, | With the <var class="product">Sir2000 User Language Tools</var>, | ||
you can control the error detection algoritm on a system level, with | you can control the error detection algoritm on a system level, with | ||
user-level and request-level overrides. | user-level and request-level overrides. | ||
These error control features apply to both the <var class="product">Rocket M204</var> date | These error control features apply to both the <var class="product">Rocket M204</var> date and datetime $functions. In addition, all $Sir_Date<i>xxx</i> datetime $functions (excepting <var>$Sir_DateFmt</var>) have an optional error control argument, which allows you to override the error handling for the operation of a single $function call. | ||
and | |||
$functions (excepting <var>$Sir_DateFmt</var>) have an optional error control | |||
argument, which allows you to override the error handling for the | |||
operation of a single $function call. | |||
==$Sir_Datexxx CENTSPAN argument== | ==$Sir_Datexxx CENTSPAN argument== | ||
Many of the $ | Many of the [[List of $functions#datetime|$Sir_Date<i>xxx</i>]] functions accept an optional argument containing a <var>[[#Using CENTSPAN|CENTSPAN]]</var> value to be used for the call. | ||
containing a <var>CENTSPAN</var> value to be used for the call. | The default value of any <var>CENTSPAN</var> argument is <code>-50</code>, excepting the [[Janus Web Server $functions#Date processing $functions|$Web_Date2<i>xx</i>]] functions without a format argument, in which case the <var>CENTSPAN</var> argument is ignored and a <var>CENTSPAN</var> of <code>1990</code> is used. | ||
The default value of any <var>CENTSPAN</var> argument is -50, excepting | |||
the $ | |||
case the <var>CENTSPAN</var> argument is ignored and a <var>CENTSPAN</var> of 1990 is used. | |||
The default value should be adequate in most cases; if you have | The default value should be adequate in most cases; if you have carefully determined it should be different in some application, code the value on the relevant $function invocations. | ||
carefully determined it should be different in some application, | |||
code the value on the relevant | |||
For a different approach to the default (a 100-year period), see the description of the <var>[[CENTSPLT parameter|CENTSPLT]]</var> and <var>[[DEFCENT parameter|DEFCENT]]</var> parameters and $function arguments. | |||
==Other $functions using date values== | ==Other $functions using date values== | ||
In addition to the | In addition to the $Date<i>xxx</i> and $Sir_Date<i>xxx</i> functions, there are some $functions that deal with dates from <var class="product">Model 204</var> internal structures. | ||
These $functions and any date processing considerations are described below: | |||
$functions that deal with dates from <var class="product">Model 204</var> internal structures. | <table> | ||
These $functions and any date processing considerations are: | |||
<table | |||
<tr><th><var>$FiniTim</var></th> | <tr><th><var>$FiniTim</var></th> | ||
<td>This $function returns the file initialization date and time, using a two-digit year. </td></tr> | <td>This $function returns the file initialization date and time, using a two-digit year. </td></tr> | ||
<tr><th><var>$ListSrt</var></th> | <tr><th><var>$ListSrt</var></th> | ||
<td>This $function sorts a $list; it allows you to specify a '''C''' modifier of the sort key to indicate | <td>This $function sorts a $list; it allows you to specify a '''C''' modifier of the sort key to indicate | ||
a two-digit year, which it will then sort using a <var>CENTSPAN</var> of 1975. </td></tr> | a two-digit year, which it will then sort using a <var>CENTSPAN</var> of 1975. </td></tr> | ||
<tr><th><var>$PrcLEx</var> or <var>$PrcLExG</var></th> | <tr><th><var>$PrcLEx</var> or <var>$PrcLExG</var></th> | ||
<td>These $functions retrieve a $list of information about procedures in file or group. | <td>These $functions retrieve a $list of information about procedures in file or group. | ||
Line 616: | Line 173: | ||
<li>You may sort the $list using a two-digit year if you use the '''C''' modifier of <var>$ListSrt</var>. | <li>You may sort the $list using a two-digit year if you use the '''C''' modifier of <var>$ListSrt</var>. | ||
<li>The fourth argument, which specifies the last-modified date selection criterion, is passed as a two-digit year, using a <var>CENTSPAN</var> of 1975. | <li>The fourth argument, which specifies the last-modified date selection criterion, is passed as a two-digit year, using a <var>CENTSPAN</var> of 1975. | ||
</ul> | </ul></td></tr> | ||
<tr><th nowrap><var>$Proc_List</var> or <var>$Proc_ListG</var></th> | <tr><th nowrap><var>$Proc_List</var> or <var>$Proc_ListG</var></th> | ||
<td>These $functions retrieve a $list of information about procedures in file/group. | <td>These $functions retrieve a $list of information about procedures in file/group. | ||
Line 623: | Line 181: | ||
<li>The fourth argument, which specifies the last-modified date selection | <li>The fourth argument, which specifies the last-modified date selection | ||
criterion, is passed as a two-digit year, using a <var>CENTSPAN</var> of 1975. | criterion, is passed as a two-digit year, using a <var>CENTSPAN</var> of 1975. | ||
</ul> | </ul></td></tr> | ||
<tr><th><var>$SirJGet</var></th> | <tr><th><var>$SirJGet</var></th> | ||
<td>This $function retrieves audit trail data into a $list. | <td>This $function retrieves audit trail data into a $list. | ||
The arguments that specify the start and end time to extract | The arguments that specify the start and end time to extract | ||
are passed as two-digit years, using a <var>CENTSPAN</var> of 1990. | are passed as two-digit years, using a <var>CENTSPAN</var> of 1990. </td></tr> | ||
<tr><th><var>$SirTime</var></th> | <tr><th><var>$SirTime</var></th> | ||
<td>This $function returns the current date and time, using a two-digit year. | <td>This $function returns the current date and time, using a two-digit year.</td></tr> | ||
</table> | </table> | ||
==Benefits of | ==<b id="benefits"></b>Benefits of $Sir_Date<i>xxx</i> datetime processing== | ||
Following is a list of benefits offered by | <p> | ||
To provide concrete comparisons, there | Following is a list of benefits offered by $Sir_Date<i>xxx</i> (and Sir2000) datetime processing. To provide concrete comparisons, there | ||
are some references to the standard <var class="product">Model 204</var> date $functions provided | are some references to the standard <var class="product">Model 204</var> date $functions provided by <var class="product">Rocket M204</var>. </p> | ||
by <var class="product">Rocket M204</var>. | <p> | ||
For Fast/Unload specific remarks, see [[Fast/Unload datetime processing considerations#Benefits of Fast/Unload datetime processing|Benefits of Fast/Unload datetime processing]]. | |||
</p> | |||
< | {{Template:Benefits of $Sir Datexxx datetime processing}} | ||
[[Category: SOUL]] | |||
Latest revision as of 19:41, 20 April 2018
The discussion of datetime processing on this page applies to $functions, #functions, and commands added to the Rocket M204 products in version 7.5 of Model 204. These added functions and commands share "datetime formats" that differ from those in the pre-7.5 standard Model 204 related date $functions.
Although the discussion here tends to emphasize the SOUL $Sir_Datexxx $functions, these datetime format strings are used in several Rocket Model 204 add-on products, including:
- Fast/Unload
- Janus Open Client
- Janus Open Server
- Janus Specialty Data Store
- Janus Web Server
- SirDBA
- Sir2000 Field Migration Facility
- Sir2000 User Language Tools
Datetime formats
The string representation of a date is described by a datetime format. This value is a character string, composed of the concatenation of these:
- Tokens
For example, YYYY for a four-digit year, and MI for minutes.
- Separator characters
For example, forward slash (/) in MM/DD/YY for two-digit month, day, and year separated by slashes.
These datetime format strings are used in many methods, commands, and $functions. Since all methods that operate on strings are functions, methods and $functions are collectively referred to as functions on this page.
The rules for these datetime format strings are consistent wherever these formats are used, though certain uses of these strings might impose extra restrictions. For example, a leading blank may match an HH, DD, or MM token in SOUL methods, but it may not in some cases in other Rocket M204 products.
Datetime format rules
Certain rules are applied to determine if a format is valid. The basic rules are:
- If a format string contains a numeric datetime token (that is, ND, NM, or NS), then the format string must consist of only one token. Numeric datetime tokens are supported only in format strings for the Sir2000 Field Migration Facility.
- You must specify at least one time, weekday, or date (except for Sir2000 Field Migration Facility alternate or error formats).
- Except for "weekday," you must not specify redundant information.
More specifically this means:
- Except for I, no token can be specified twice.
- At most one year format (contains Y) can be specified.
- At most one month format (contains MON, Mon, or MM) can be specified.
- At most one day format (DD or Day) can be specified.
- At most one weekday format (WKD, Wkd, WKDAY, or Wkday) can be specified.
- If AM is specified, then PM cannot be specified.
- At most one fractions-of-a-second format (contains X) can be specified.
- If DDD is specified, then neither a day nor month format can be specified.
- If ZYY is specified in a format string, no other token that denotes a variable-length value may be used.
- If a format string contains other tokens that denote variable length values, then an * token may only appear as the last character of the format string.
- The DAY token may not be immediately followed by another token whose value may be numeric, regardless of whether the following token represents a variable length value. Thus, DAY may not be followed by *, I, YY, YYYY, CYY, MM, HH, MI, SS, X, XX, or XXX; DAY may not be followed by a decimal digit separator; and DAY may not be followed by a quote followed by a decimal digit.
- For non-Janus add-on products:
When a pair of format strings are used for transforming date values, for example, for $Sir_DateCnv, #DATECNV, or processing of updates to fields that are connected by a SIRFIELD RELATE command, additional rules apply to the pattern matching tokens:
- If one of the format strings includes one or more I tokens, then the other format string must contain the same number of I tokens. Note that the placement of I tokens within the format strings is not restricted. The I tokens are processed left to right, with each character from the input string that corresponds to the nth I token in the input format being copied unchanged to the character position in the output string that corresponds to the nth I token in the output format.
- If one of the format strings contains an * token, then the other format string must also contain an * token. All of the characters from the input string that correspond to the * token in the input format, if any, are copied unaltered to the output string, beginning in the position that corresponds to the * token in the output format.
- The maximum length of a format string is 100 characters (except 31 for SirDBA).
Datetime format tokens
The valid tokens in a date format are shown in the following list. In general, the output format rule for a token is shown: that is, the result when a value from an SQL client is converted to operate on a DATETIME field, or the result when a DATETIME or SMALLDATETIME numeric value is converted to a datetime character string in a SOUL %variable.
The input format rules are less strict: for example, all of the tokens that convert from an alphabetic string (for example, MON) work with any case string (for example, jan
or JAN
or Jan
).
For some of the functions, the input format rule for a token is the same as the output format rule; this is the definition of "strict date format matching." However, non-strict functions sometimes allow a string to match a token on input that would not be produced by that token on output.
All of the tokens that match alphabetic strings (for example, MON) match any case for non-strict matching. For other tokens that have differing strict and non-strict matching rules, usage notes for them are contained below in Datetime and format examples. Each input datetime format argument in the description of a function specifies whether the use of the format observes strict or non-strict format matching.
NM | Numeric datetime value containing the number of milliseconds (1/1000 of a second) since January 1, 1900 at 12:00 AM. (This token is allowed only in the Sir2000 Field Migration Facility.) |
---|---|
NS | Numeric datetime value containing the number seconds since January 1, 1900 at 12:00 AM. (This token is allowed only in the Sir2000 Field Migration Facility.) |
ND | Numeric date value containing the number of days since January 1, 1900. (This token is allowed only in the Sir2000 Field Migration Facility.) |
* | Ignore entire variable-length substring matching pattern, if any, only when retrieving a date value.
Substitute with null string when only creating a date value. When copying date values, copy entire variable-length substring matching pattern, if any, from the input value to the location identified by * token in output string. |
I | For Janus products and SirDBA: ignore corresponding input character.
For other products: ignore corresponding input character when only retrieving a date value. Store a blank in corresponding output character when only creating a date value. When copying date values, copy each character matching an I token from from the input value to the location in the output string identified by the corresponding I token in the output format. |
" | Following character is "quoted," that is, it acts as a separator character. |
YYYY | 4-digit year |
YY | 2-digit year |
CYY | Year minus 1900 (3 digits, including any leading zero). |
ZYY | Year minus 1900, two-digit or three-digit year number, excluding any leading zero (variable length data).
Non-strict functions allow a three-digit number with leading zero on input, but any number less than 100 always produces a two-digit number on output. See Datetime and format examples. |
MONTH | Full month name (uppercase variable length).
For Janus products: if used as an argument to a method or $function for converting from a string, this is the same as Month. Non-strict functions allow any mixture of uppercase and lowercase on input, but all-uppercase is always produced on output. |
Month | Full month name (mixed-case variable length).
For Janus products: if used as an argument to a function for converting from a string, this is the same as MONTH. Non-strict functions allow any mixture of uppercase and lowercase on input, but initial uppercase letter followed by all lowercase is always produced on output. |
MON | Three-character month abbreviation (uppercase).
For Janus products: if used as an argument to a function for converting from a string, this is the same as Mon. Non-strict functions allow any mixture of uppercase and lowercase on input, but all-uppercase is always produced on output. |
Mon | Three-character month abbreviation (mixed case).
For Janus products: if used as an argument to a function for converting from a string, this is the same as MON. Non-strict functions allow any mixture of uppercase and lowercase on input, but initial uppercase letter followed by all-lowercase is always produced on output. |
MM | Two-digit month number.
For Janus products: if used as an argument to a function for converting from a string, this is the same as BM (leading blank is allowed). Non-strict functions allow a two-character number with leading blank on input, but two decimal digits are always produced on output. Note: A common mistake is to use MM instead of MI for minutes. |
BM | Two-character month number.
For Janus products: if used as an argument to a function for converting from a string, this is the same as MM. If less than 10, first character is blank. Non-strict functions allow a two-digit number with leading zero on input, but any number less than 10 always produces a blank followed by a decimal digit on output. |
DDD | Three-digit Julian day number. |
DD | Two-digit day number.
For Janus products: if used as an argument to a function for converting from a string, this is the same as BD (leading blank is allowed). Non-strict functions allow a two-character number with leading blank on input, but two decimal digits are always produced on output. |
BD | Two-character day number. If less than 10, first character is blank.
For Janus products: if used as an argument to a function for converting from a string, this is the same as DD. Non-strict functions allow a two-digit number with leading zero on input, but any number less than 10 always produces a blank followed by a decimal digit on output. |
DAY | One-digit or two-digit day number (variable length data).
Non-strict functions allow a two-digit number with leading zero on input, but any number less than 10 always produces a one-digit number on output. |
WKDAY | Full day of week name (upper case variable length).
For Janus products: if used as an argument to a function for converting from a string, this is the same as Wkday. Non-strict functions allow any mixture of uppercase and lowercase on input, but all-uppercase is always produced on output. |
Wkday | Full day of week name (mixed-case variable length).
For Janus products: if used as an argument to a function for converting from a string, this is the same as WKDAY. Non-strict functions allow any mixture of uppercase and lowercase on input, but initial uppercase letter followed by all-lowercase is always produced on output. |
WKD | Three-character day of week abbreviation (uppercase).
For Janus products: if used as an argument to a function for converting from a string, this is the same as Wkd. Non-strict functions allow any mixture of uppercase and lowercase on input, but all-uppercase is always produced on output. |
Wkd | Three-character day of week abbreviation (mixed case).
For Janus products: if used as an argument to a function for converting from a string, this is the same as WKD. Non-strict functions allow any mixture of uppercase and lowercase on input, but initial uppercase letter followed by all-lowercase is always produced on output. |
HH | Two-digit hour number.
Non-strict functions allow a two-character number with leading blank on input, but two decimal digits are always produced on output. For Janus products: if used as an argument to a function for converting from a string, this is the same as BH (leading blank is allowed). |
BH | Two-digit hour number. If less than 10, first character is blank.
For Janus products: if used as an argument to a function for converting from a string, this is the same as HH. Non-strict functions allow a two-digit number with leading zero on input, but any number less than 10 always produces a blank followed by a decimal digit on output. |
MI | Two-digit minute number.
Note: A common mistake is to use MM instead of MI for minutes. |
SS | Two-digit second number. |
X | Tenths of a second. |
XX | Hundredths of a second. |
XXX | Thousandths of a second (milliseconds). |
AM | AM/PM indicator. |
PM | AM/PM indicator. |
Datetime format separators
The valid separators in a date format are:
- blank
- apostrophe (')
- slash (/)
- colon (:)
- hyphen (-)
- back slash (\)
- period (.)
- comma (,)
- underscore (_)
- left parenthesis ( ( )
- right parenthesis ( ) )
- plus (+)
- vertical bar (|)
- equal (=)
- ampersand (&)
- at sign (@)
- sharp (#)
- the decimal digits (0 - 9).
In addition, any character may be a separator character if preceded by the quoting character (").
See Datetime and format examples for examples that include the use of various separator characters.
Valid datetimes
For a datetime string to be valid it must meet the following criteria:
- Its length must be less than 128 characters.
- It must be compatible with its corresponding format string.
- It must represent a valid date and/or time.
For example, at most 23:59:59.999 for a time, 01-12 for a month, 01-31 or less (depending on the month) for a day, February 29 is only valid in leap years (only centuries divisible by 4 are leap years: 2000 is but neither 1800, 1900, nor 2100 are).
Note: weekdays are not checked for consistency against the date. For example, both
Saturday, 02/15/97
andFriday, 02/15/97
are valid. - It must be within the date range allowed for the corresponding format.
A datetime string used with a CYY or ZYY format can only represent dates from 1900 to 2899, inclusive. Except for SirDBA, a datetime string used with a YY format can only represent dates in a range of 100 or less years, as determined by CENTSPAN and SPANSIZE. The valid range of dates for all other formats is from
1 January 1753
thru31 December 9999
.
Processing dates with two-digit year values
A date field with only two digits for the year value is capable of representing a range of up to one hundred years.
When we compare a pair of two-digit year values, we are accustomed to
thinking of the century as fixed, so that all dates are either 19xx
or 20xx
.
However, a date field with two-digit year values can actually represent
dates from two different centuries, provided that the range of dates does not exceed 100 years.
Using CENTSPAN
CENTSPAN provides a mechanism for unambiguously converting dates with two-digit year values into dates with four-digit year values. The CENTSPAN mechanism allows two-digit year values to span two centuries without confusion. CENTSPAN identifies the four-digit year value that is the start of a range of years represented by the two-digit year values.
CENTSPAN may be specified as an absolute unsigned four-digit value between 1753 and 9999, or it may be specified as a relative signed value between -99 and +99, inclusive. A relative CENTSPAN value is dynamically converted to an effective absolute value before it is used to perform a YY to YYYY conversion. The effective CENTSPAN value is formed by adding the relative CENTSPAN to the current four-digit year value at the time the relative value is converted.
A simple algorithm is used to convert a two-digit year value (YY) to a four-digit year value, using a four-digit absolute or effective CENTSPAN value (HHLL). If the two-digit year value is less than the low-order two digits of the CENTSPAN value, then the resulting century is one greater than the high-order two digits of the CENTSPAN value. Otherwise the resulting century is the same as the high-order two digits of the CENTSPAN value.
Using all one hundred available years for mapping two-digit year values can cause significant confusion and result in data integrity errors. This is because dates just above and just below the 100-year window are mapped to the other end of the window. From the previous example, the date "47" will be interpreted as 1947, when it could have conceivably been 2047. Simlarly, the date "46" will be interpreted as 2046, when it might have been 1946.
If CENTSPAN is set to a value that is too high, dates that are just prior to CENTSPAN will appear to occur 100 years hence.
If CENTSPAN is set to a value that is too low, dates that fall just after CENTSPAN+99
will appear to have occurred 100 years earlier. A full one-hundred year window also can not detect attempts to represent more than one hundred years of values with a two-digit year.
Using SPANSIZE
To protect from the ambiguities that can occur at each end of the 100-year window defined by CENTSPAN, SPANSIZE is used to restrict the size of the window used for mapping two-digit year values. The effect is to create two guard bands', one just below the date window and one just above. An attempt to represent a date value that lands in a guard band produces an error.
Each guard band contains CENTSPAN - SPANSIZE
years, hence a SPANSIZE of 100 removes the protection. The default SPANSIZE is a value that you can customize in your load module.
If you do not customize it, the value of SPANSIZE is 90, which provides protection for two ten-year windows: one below the CENTSPAN setting and one starting at CENTSPAN+90
.
From the previous example:
An attempt to represent the values "37" through "46" is rejected. This protects the range 1937 through 1946 as well as the range 2037 through 2046. Note that an intended value of 2047, expressed as "47" will be accepted and interpreted as 1947. In general a smaller SPANSIZE provides the highest assurance of correct mappings. However, any setting of SPANSIZE less than 100 will probably detect the case where a range greater than one hundred years is being used.
Strict and non-strict format matching
As mentioned above in Datetime formats, for some of the functions, the input format rule for a token is the same as the output format rule. This is the definition of "strict date format matching." However, non-strict functions sometimes allow a string to match a token on input that would not be produced by that token on output.
The types of strict matching are as follows:
Alpha tokens | For alphabetic tokens (for example, Month), a strict match requires the input value to be the correct case. For example, the MON token is strictly matched by JAN but not by Jan , and the reverse is true for the Mon token. For non-strict matching, the alphabetic tokens are matched by any combination of uppercase and lowercase input. |
---|---|
HH, MM, DD | For these tokens, a strict match requires a leading zero for values less than 10. For non-strict matching, a value less than 10 can also be represented by a leading blank followed by a single numeric digit. |
BH, BM, BD | For these tokens, a strict match requires a leading blank for values less than 10. For non-strict matching, a value less than 10 can also be represented by a leading zero followed by a numeric digit. |
DAY | For this token, a strict match requires a single digit for values less than 10. For non-strict matching, a value less than 10 can also be represented by a leading zero followed by a numeric digit. |
ZYY | For this token, a strict match requires two digits for values less than 100. For non-strict matching, a value less than 100 can also be represented by a leading zero followed by a two numeric digits. |
The strict functions are only available in the Sir2000 User Language Tools. With non-strict date $functions, however, you can use the following technique to check a datetime string using strict rules:
If date Eq '' Or date NE $Sir_NM2Date(- $Sir_Date2NM(date, fmt), fmt) Then error handling End If
Or, using SOUL OO functions:
if date eq '' or date ne date:stringToMilliseconds(format):millisecondsToString(format) then error handling end if
Datetime and format examples
The extensive set of format tokens is shown above in Datetime format tokens. These tokens and the various separator characters can be combined in almost limitless possibility, giving rise to an extremely large set of datetime formats.
This section provides examples of some common datetime formats, and also tries to explain the use of some of the format tokens that might not be obvious. It also has examples for formats whose usage differs depending on whether strict or non-strict format matching is involved.
Each example format is explained and also presented with some matching datetimes; again, bear in mind that these tokens can be combined in very many ways and only a very few are shown here. It is assumed that these examples are invoked sometime between the years 1998-2040, as the basis for relative CENTSPAN calculations.
Note: For comparable Fast/Unload examples, see Fast/Unload datetime and format examples.
YYMMDD | This is the common six-digit date format which supports sort order if all dates are within a single century.
The following SOUL code fragment prints the value If $sir_date2nd('960229', 'YYMMDD') > -9E12 Then Print 'OK' End If
For Sir2000 User Language Tools users, the following statement prints the value print $sir_datechk('YYMMDD', '960229') |
---|---|
YYYYMMDD | This is the common eight-digit date format which supports sort order with dates in two centuries.
The following SOUL code fragment prints the value %n = $sir_date2nd('921212', 'YYMMDD') Print $sir_nd2date(%n, 'YYYYMMDD')
For Sir2000 User Language Tools users, the following statement prints the value print $sir_datecnv('YYMMDD', 'YYYYMMDD', '921212') |
MM/DD/YY | This is the U.S. six-digit date format for display. The value 12/14/97 matches this format.
The following SOUL code fragment prints the value If $sir_date2nd('12/14/94', 'MM/DD/YY') > -9E12 Then Print 'OK' End If
For Sir2000 User Language Tools users, the following statement prints the value print $sir_datechk('MM/DD/YY', '12/14/94')
|
DD.MM.YY | This is a European six-digit date format for display. The value 14.12.97 matches this format.
The following SOUL code fragment prints the value If $sir_date2nd('14.12.94', 'DD.MM.YY') > -9E12 Then Print 'OK' End If
For Sir2000 User Language Tools users, the following statement prints the value print $sir_datechk('DD.MM.YY', '14.12.94')
|
Wkday, DAY Month YYYY "A"T HH:MI | This is a format that could be used for report headers.
The following SOUL statement prints a value like print $sir_date('Wkday, DAY Month YYYY "A"T HH:MI')
|
YYIIII | This format might be used for data that contains a two-digit year prefixing other information, such as a sequence number. The value 92A123 matches this format.
The following SOUL code fragment prints the value %d = $sir_date2nd('92ABCD', 'YYIIII') Print $sir_nd2date(%d + 10*365.25, 'YY')
For Sir2000 User Language Tools users, the following statement prints the value print $sir_datecnv('YYIIII', 'YYYYIIII', '92ABCD') Note: When a pair of format strings are used for transforming date values, for example for $Sir_DateCnv or processing of updates to SIRFIELD RELATE fields, both formats must have the same number of I tokens. The $functions with both an input and output format, for example $Sir_DateCnv, are only available in the Sir2000 User Language Tools; SIRFIELD is part of the Sir2000 Field Migration Facility. |
YY* | This format might be used for data that contains a two-digit year prefixing other information, such as a sequence number, when the other information is variable length. The values 92 and 92ABC123 match this format.
The following SOUL code fragment
prints the values If $sir_date2nd('92', 'YY*') > -9E12 Then Print 'OK' End If IF $sir_date2nd('1992ABC', 'YYYY*') > -9E12 THEN Print 'OK' End If
For Sir2000 User Language Tools users, the following statements print the values print $sir_datecnv('YY*', 'YYYY*', '92') print $sir_datecnv('YY*', 'YYYY*', '92XYZ')
|
CYYDDD | This is a compact six-digit date format with explicit century information, from 1900 through and including 2899. The value 097031 (representing 31 January 1997) matches this format.
The following SOUL fragment prints the value If $sir_date2nd('097031', 'CYYDDD') > -9E12 Then Print 'OK' End If
For Sir2000 User Language Tools users, the following statement prints the value print $sir_datechk('CYYDDD', '097031') |
ZYYMMDD | This is a compact six- or seven-digit date format with explicit century information, from 1900 through and including 2899, that can often be used with "old" YYMMDD date values in the 1900s. The values 970501 (representing 1 May 1997) and 1000501 (representing 1 May 2000) match this format.
The following SOUL fragment prints the values * Check 1 Dec, 1997: If $sir_date2nd('971201', 'ZYYMMDD') > -9E12 Then Print 'OK' End If * Check 1 Dec, 2000: If $sir_date2nd('1001201', 'ZYYMMDD') > -9E12 Then Print 'OK' End If
For Sir2000 User Language Tools users, the following statements print the values * Check 1 Dec, 1997: print $sir_datechk('ZYYMMDD', '971201') * Check 1 Dec, 2000: print $sir_datechk('ZYYMMDD', '1001201')
|
YY0000 | Decimal digits can be used as separator characters. The value 980000 matches this format.
The following SOUL fragment prints the value %n = $sir_date2nd('92000', 'YY000') Print $sir_nd2date(%n, 'YYYY"N"A')
For Sir2000 User Language Tools users, the following SOUL statement prints the value Print $sir_datecnv('YY0000', 'YYYY"N"A', '920000') Note: Numeric separators, unlike alphabetic separators, do not need to be preceded by a double-quote character ("). |
Datetime error handling
Note: For a comparable Fast/Unload discussion, see Fast/Unload datetime error handling.
Due to an invalid argument value to a datetime function, any of the following errors can occur:
- Invalid datetime format specification
- Datetime string not matching format
- Datetime out of range for the format
- Invalid CENTSPAN value
- Datetime out of range for CENTSPAN/SPANSIZE combination
One way to detect these errors is to check for the appropriate error return value:
- Functions using a numeric value to represent a datetime, and
$Sir_Date, have error return values of
-9.E12
or a null string for numeric or string result functions, respectively. - $Functions (other than $Sir_Date) that only manipulate strings and associated datetime formats have error return values of a variable number of asterisks (or, in the case of $Sir_DateDif, the value 99,999,999). $Sir_DateDif and the date $functions that return a variable number of asterisks as error indication are available only with the Sir2000 User Language Tools.
If you are authorized to use the Sir2000 User Language Tools, you can modify the error detection algorithm so that warning messages or request cancellation occur when a datetime error occurs. One significant advantage of this product is that you can add a great deal of error detection to applications without modifying any SOUL code. Also, for case 2, above, thorough error detection of error return values is somewhat complex.
With the Sir2000 User Language Tools, you can control the error detection algoritm on a system level, with user-level and request-level overrides. These error control features apply to both the Rocket M204 date and datetime $functions. In addition, all $Sir_Datexxx datetime $functions (excepting $Sir_DateFmt) have an optional error control argument, which allows you to override the error handling for the operation of a single $function call.
$Sir_Datexxx CENTSPAN argument
Many of the $Sir_Datexxx functions accept an optional argument containing a CENTSPAN value to be used for the call.
The default value of any CENTSPAN argument is -50
, excepting the $Web_Date2xx functions without a format argument, in which case the CENTSPAN argument is ignored and a CENTSPAN of 1990
is used.
The default value should be adequate in most cases; if you have carefully determined it should be different in some application, code the value on the relevant $function invocations.
For a different approach to the default (a 100-year period), see the description of the CENTSPLT and DEFCENT parameters and $function arguments.
Other $functions using date values
In addition to the $Datexxx and $Sir_Datexxx functions, there are some $functions that deal with dates from Model 204 internal structures. These $functions and any date processing considerations are described below:
$FiniTim | This $function returns the file initialization date and time, using a two-digit year. |
---|---|
$ListSrt | This $function sorts a $list; it allows you to specify a C modifier of the sort key to indicate a two-digit year, which it will then sort using a CENTSPAN of 1975. |
$PrcLEx or $PrcLExG | These $functions retrieve a $list of information about procedures in file or group.
|
$Proc_List or $Proc_ListG | These $functions retrieve a $list of information about procedures in file/group.
|
$SirJGet | This $function retrieves audit trail data into a $list.
The arguments that specify the start and end time to extract are passed as two-digit years, using a CENTSPAN of 1990. |
$SirTime | This $function returns the current date and time, using a two-digit year. |
Benefits of $Sir_Datexxx datetime processing
Following is a list of benefits offered by $Sir_Datexxx (and Sir2000) datetime processing. To provide concrete comparisons, there are some references to the standard Model 204 date $functions provided by Rocket M204.
For Fast/Unload specific remarks, see Benefits of Fast/Unload datetime processing.
SPANSIZE | The SPANSIZE processing creates a very strong barrier to detecting otherwise unnoticed two-digit year processing errors. |
---|---|
Relative CENTSPAN | The relative CENTSPAN specification (for example, -50 ) lets you maintain a flexible "rolling" window for two-digit year processing. |
Default CENTSPAN | One significant advantage of a relative CENTSPAN is that it allows the default (1990 for $Web_Date2xx functions without a format, and -50 otherwise) of a reasonable value without parameter changes in all batch and Online jobs. |
Format tokens | There is a very large set of tokens in the Sir2000 and $SirDatexxx datetime formats. For example, there are four different tokens representing the day of the week, and time of day can be represented. Standard SOUL date formats do not have any day-of-week or time-of-day tokens, and other standard SOUL token variations, for example, CYY versus ZYY, are done by a complex argument setting. |
Pattern match tokens | The Sir2000 and $SirDatexxx datetime formats can contain single-character (I ) or variable-length character (* ) match-any tokens in datetime formats. For example, you can specify that a string has an embedded year, and you can process that year as a date. |
Format-free representations | Non-string datetime values allow you to pass around dates simply as numbers, without the complexities of carrying the corresponding string format (you only need to establish the scale to operate on a value). |
Operating on numeric representations | Numeric date values can be operated on directly with SOUL, especially allowing you to add datetime differences (for example, + ), rather than calling a $DateChg $function and providing a format. |
Time | All Sir2000 and $SirDatexxx datetime $functions allow any reference to a "date" to include time of day. The only standard SOUL datetime $function that provides a time of day is $Time, the current time of day, in one fixed format. |
$Sir_Date formats | $Sir_Date lets you specify any format to return the current date and time. $Date has only a few numeric codes for a few formats. |
Error control arguments | Sir2000 User Language Tools provides error handling control that applies to all datetime $functions, including standard SOUL. Additionally, the Sir2000 and $SirDatexxx datetime $functions (except $Sir_DateFmt) let you specify error control for a single $function invocation. |
Error values of numeric date $functions | The $functions that use non-string datetime values provide very uniform error return values: -9.E12 or a null string, for numeric or string result $functions, respectively. |