Datetime string formats: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (link repair)
m (misc cleanup)
Line 1: Line 1:
==Datetime formats==
==Datetime formats==
The string representation of a date is described by a ''datetime format''.
The string representation of a date is described by a '''datetime format'''.
This value is a character string, composed of the concatenation of
This value is a character string, composed of the concatenation of
tokens (for example, "YYYY" for a four-digit year, and "MI" for minutes) and separator characters
tokens (for example, <code>YYYY</code> for a four-digit year, and <code>MI</code> for minutes) and separator characters
(for example, "/" in "MM/DD/YY" for two-digit month, day, and year separated by slashes).
(for example, <code>/</code> in <code>MM/DD/YY</code> for two-digit month, day, and year separated by slashes).
   
   
These ''datetime format'' strings are used in many methods, commands, and
These datetime format strings are used in many methods, commands, and
$functions. Since all methods that operate on strings are functions, methods
$functions. Since all methods that operate on strings are functions, methods and $functions are collectively referred to as ''functions'' on this page.
and $functions are collectively referred to as ''functions'' on this page.
   
   
The rules for these ''datetime format'' strings are consistent
The rules for these datetime format strings are consistent
throughout all Sirius products, though certain uses of these strings
throughout all Sirius functions, though certain uses of these strings
might impose extra restrictions.
might impose extra restrictions.
For example, a leading blank may match an HH, DD, or MM token in
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]],
[[Object oriented programming in SOUL|SOUL methods]],
but it may not in some cases in other Rocket products.
but it may not in some cases in other Rocket products.
Line 19: Line 18:
<ul>
<ul>
<li>If a format string contains a numeric datetime token (that is,
<li>If a format string contains a numeric datetime token (that is,
"ND", "NM", or "NS"), then the
<var>ND</var>, <var>NM</var>, or <var>NS</var>), then the
format string must consist of only one token.
format string must consist of only one token.
<!-- Numeric datetime tokens are only supported in format strings for the FMF2K.. -->
<!-- Numeric datetime tokens are only supported in format strings for the FMF2K.. -->
Line 25: Line 24:
<li>You must specify at least one time, weekday, or date. <!-- except for &FMF2K alternate or error formats. -->
<li>You must specify at least one time, weekday, or date. <!-- except for &FMF2K alternate or error formats. -->


<li>Except for "weekday", you can't specify redundant information.
<li>Except for "weekday," you must not specify redundant information.
More specifically this means:
More specifically this means:
<ul>
<ul>
<li>Except for "I", no token can be specified twice.
<li>Except for <var>I</var>, no token can be specified twice. </li>
<li>At most one year format (contains Y) can be specified.
 
<li>At most one month format (contains MON, Mon, or MM) can be specified.
<li>At most one year format (contains <var>Y</var>) can be specified.</li>
<li>At most one day format (DD or Day) can be specified.
 
<li>At most one weekday format (WKD, Wkd, WKDAY, or Wkday) can be specified.
<li>At most one month format (contains <var>MON</var>, <var>Mon</var>, or <var>MM</var>) can be specified. </li>
<li>If AM is specified, then PM can not be specified.
 
<li>At most one fractions-of-a-second format (contains X) can be specified.
<li>At most one day format (<var>DD</var> or <var>Day</var>) can be specified. </li>
<li>If DDD is specified, then neither a day nor month format can be specified.
 
<li>At most one weekday format (<var>WKD</var>, <var>Wkd</var>, <var>WKDAY</var>, or <var>Wkday</var>) can be specified. </li>
 
<li>If <var>AM</var> is specified, then <var>PM</var> can not be specified. </li>
 
<li>At most one fractions-of-a-second format (contains <var>X</var>) can be specified. </li>
 
<li>If <var>DDD</var> is specified, then neither a day nor month format can be specified. </li>
</ul>
</ul>


<li>If ZYY is specified in a format string, no other token that
<li>If <var>ZYY</var> is specified in a format string, no other token that denotes a variable-length value may be used.
denotes a variable-length value may be used.


<li>If a format string contains other tokens that denote variable
<li>If a format string contains other tokens that denote variable
length values, then an * token may only appear as the last character
length values, then an <var>*</var> token may only appear as the last character
of the format string.
of the format string.


<li>The DAY token may not be immediately followed by another token
<li>The <var>DAY</var> token may not be immediately followed by another token whose value may be numeric, regardless of whether the following
whose value may be numeric, regardless of whether the following
token represents a variable length value.
token repsents a variable length value.
Thus, <var>DAY</var> may not be followed by <var>*</var>, <var>I</var>, <var>YY</var>, <var>YYYY</var>, <var>CYY</var>, <var>MM</var>, <var>HH</var>, <var>MI</var>, <var>SS</var>,
Thus, DAY may not be followed by *, I, YY, YYYY, CYY, MM, HH, MI, SS,
<var>X</var>, <var>XX</var>, or <var>XXX</var>; <var>DAY</var> may not be followed by a decimal digit separator,
X, XX, or XXX; DAY may not be followed by a decimal digit separator,
and <var>DAY</var> may not be followed by a quote followed by a decimal digit.
and DAY may not be followed by a quote followed by a decimal digit.


<!--  
<!--  
Line 81: Line 85:
</ul>
</ul>
   
   
<p class="note"><b>Note:</b> A common mistake is to use "MM" for minutes; it should be "MI". </p>
<p class="note"><b>Note:</b> A common mistake is to use <var>MM</var> for minutes; it should be <var>MI</var>. </p>


==Datetime format tokens==
==Datetime format tokens==
Line 89: Line 93:
operate on a DATETIME field.
operate on a DATETIME field.
The '''input format rules''' which convert a value from a DATETIME
The '''input format rules''' which convert a value from a DATETIME
field are less strict; for example, all of the tokens which convert ''''from'''' an
field are less strict; for example, all of the tokens that convert ''''from'''' an
alpabetic string (for example, "MON") will properly convert a value of the field that contains
alphabetic string (for example, <var>MON</var>) properly convert a value of the field that contains
any case string (for example, "jan" or "JAN" or "Jan").
any case string (for example, <code>jan</code> or <code>JAN</code> or <code>Jan</code>).
   
   
In general, the '''output format rule''' for a token is shown, that is, the result when a DATETIME
In general, the '''output format rule''' for a token is shown, that is, the result when a DATETIME
or SMALLDATETIME numeric value is converted to a datetime character string in a <var class="product">SOUL</var> %variable.
or SMALLDATETIME numeric value is converted to a datetime character string in a <var class="product">SOUL</var> %variable.
The '''input format rules''' for $functions are less strict; for example,
The '''input format rules''' for $functions are less strict; for example,
all of the tokens which convert ''''from'''' an alpabetic string (for example, "MON")
all of the tokens which convert ''''from'''' an alpabetic string (for example, <var>MON</var>)
will allow any case string (for example, "jan" or "JAN" or "Jan").
will allow any case string (for example, <code>jan</code> or <code>JAN</code> or <code>Jan</code>).
   
   
All of the tokens that match alpabetic strings (for example, "MON")
All of the tokens that match alpabetic strings (for example, <var>MON</var>)
match any case string (for example, "jan" or "JAN" or "Jan").
match any case string (for example, <code>jan</code> or <code>JAN</code> or <code>Jan</code>).


In general, the output format rule for a token is shown.
In general, the output format rule for a token is shown.
For some of the functions the input format rule for a token is the same as the
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".
output format rule; this is the definition of "strict date format matching."
<!--
<!--
This ensures that values accepted as the update of
This ensures that values accepted as the update of
Line 113: Line 117:
on output.
on output.
   
   
All of the tokens that match alphabetic strings (for example, "MON")
All of the tokens that match alphabetic strings (for example, <var>MON</var>)
match any case for non-strict matching.
match any case for non-strict matching.
All other tokens which have differing strict and non-strict matching
All other tokens that have differing strict and non-strict matching
rules are listed under "Special date format rules" in
rules are listed under "Special date format rules" in
the index at the back of the manual, and usage notes for them are
the index at the back of the product manual, and usage notes for them are
contained in [[#Datetime and format examples|"Datetime and format examples"]].
contained in [[#Datetime and format examples|Datetime and format examples]].
Each input datetime format argument in the description of a $function
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.
specifies whether the use of the format observes strict or non-strict format matching.


<table>
<table class="thJustBold">
<!--
<!--
<tr><th>NM</th>
<tr><th>NM</th>
Line 145: Line 149:


<tr><th>"</th>
<tr><th>"</th>
<td>Following character is "quoted", that is, it acts as a separator character.</td></tr>
<td>Following character is "quoted," that is, it acts as a separator character.</td></tr>


<tr><th>YYYY</th>
<tr><th>YYYY</th>
<td>4 digit year</td></tr>
<td>4-digit year</td></tr>


<tr><th>YY</th>
<tr><th>YY</th>
<td>2 digit year</td></tr>
<td>2-digit year</td></tr>


<tr><th>CYY</th>
<tr><th>CYY</th>
Line 161: Line 165:


<tr><th>MONTH</th>
<tr><th>MONTH</th>
<td>Full month name (upper case variable length). When 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 upper and lower case on input, but all upper case is always produced on output.</td></tr>
<td>Full month name (uppercase variable length). When used as an argument to a method or $function for converting '''from''' a string, this is the same as <var>Month</var>. Non-strict functions allow any mixture of uppercase and lowercase on input, but all-uppercase is always produced on output.</td></tr>


<tr><th>Month</th>
<tr><th>Month</th>
<td>Full month name (mixed case variable length). When 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 upper and lower case on input, but initial upper case letter followed by all lower case is always produced on output.</td></tr>
<td>Full month name (mixed-case variable length). When used as an argument to a function for converting '''from''' a string, this is the same as <var>MONTH</var>. 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.</td></tr>


<tr><th>MON</th>
<tr><th>MON</th>
<td>Three character month abbreviation (uppercase).
<td>Three-character month abbreviation (uppercase).
When 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 upper and lower case on input, but all upper case is always produced on output.</td></tr>
When used as an argument to a function for converting '''from''' a string, this is the same as <var>Mon</var>. Non-strict functions allow any mixture of uppercase and lowercase on input, but all-uppercase is always produced on output.</td></tr>


<tr><th>Mon</th>
<tr><th>Mon</th>
<td>Three character month abbreviation (mixed case). When 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 upper and lowercase on input, but initial uppercase letter followed by all lowercase is always produced on output.</td></tr>
<td>Three-character month abbreviation (mixed case). When used as an argument to a function for converting '''from''' a string, this is the same as <var>MON</var>. 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.</td></tr>


<tr><th>MM</th>
<tr><th>MM</th>
<td>Two-digit month number. When 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.</td></tr>
<td>Two-digit month number. When used as an argument to a function for converting '''from''' a string, this is the same as <var>BM</var> (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.</td></tr>


<tr><th>BM</th>
<tr><th>BM</th>
<td>Two-character month number. When 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.</td></tr>
<td>Two-character month number. When used as an argument to a function for converting '''from''' a string, this is the same as <var>MM</var>. 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.</td></tr>


<tr><th>DDD</th>
<tr><th>DDD</th>
<td>Three-digit Julian day number</td></tr>
<td>Three-digit Julian day number</td></tr>
<tr><th>DD<td>Two-digit day number.
<tr><th>DD<td>Two-digit day number.
When 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.</td></tr>
When used as an argument to a function for converting '''from''' a string, this is the same as <var>BD</var> (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.</td></tr>


<tr><th>BD</th>
<tr><th>BD</th>
<td>Two-character day number. When used as an argument to a function for converting '''from''' a string, this is the same as DD. 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.
<td>Two-character day number. When used as an argument to a function for converting '''from''' a string, this is the same as <var>DD</var>. 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.


<tr><th>DAY</th>
<tr><th>DAY</th>
Line 193: Line 197:
<tr><th>WKDAY</th>
<tr><th>WKDAY</th>
<td>Full day of week name (upper case variable length).
<td>Full day of week name (upper case variable length).
When 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.</td></tr>
When used as an argument to a function for converting '''from''' a string, this is the same as <var>Wkday</var>. Non-strict functions allow any mixture of uppercase and lowercase on input, but all-uppercase is always produced on output.</td></tr>


<tr><th>Wkday</th>
<tr><th>Wkday</th>
<td>Full day of week name (mixed-case variable length). When 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.</td></tr>
<td>Full day of week name (mixed-case variable length). When used as an argument to a function for converting '''from''' a string, this is the same as <var>WKDAY</var>. 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.</td></tr>


<tr><th>WKD</th>
<tr><th>WKD</th>
<td>Three-character day of week abbreviation (uppercase). When 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.</td></tr>
<td>Three-character day of week abbreviation (uppercase). When used as an argument to a function for converting '''from''' a string, this is the same as <var>Wkd</var>. Non-strict functions allow any mixture of uppercase and lowercase on input, but all-uppercase is always produced on output.</td></tr>


<tr><th>Wkd</th>
<tr><th>Wkd</th>
<td>Three-character day of week abbreviation (mixed case).
<td>Three-character day of week abbreviation (mixed case).
When used as an argument to a function for converting '''from''' a string, this is the same as WKD.
When used as an argument to a function for converting '''from''' a string, this is the same as <var>WKD</var>.
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.</td></tr>
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.</td></tr>


<tr><th>HH</th>
<tr><th>HH</th>
<td>Two-digit hour number.
<td>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. When used as an argument to a function for converting '''from''' a string, this is the same as BH (leading blank is allowed).</td></tr>
Non-strict functions allow a two-character number with leading blank on input, but two decimal digits are always produced on output. When used as an argument to a function for converting '''from''' a string, this is the same as <var>BH</var> (leading blank is allowed).</td></tr>


<tr><th>BH</th>
<tr><th>BH</th>
<td>Two-digit hour number. When used as an argument to a function for converting '''from''' a string, this is the same as HH. 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.</td></tr>
<td>Two-digit hour number. When used as an argument to a function for converting '''from''' a string, this is the same as <var>HH</var>. 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.</td></tr>


<tr><th>MI</th>
<tr><th>MI</th>
<td>Two-digit minute number</td></tr>
<td>Two-digit minute number.</td></tr>


<tr><th>SS</th>
<tr><th>SS</th>
<td>Two-digit second number</td></tr>
<td>Two-digit second number.</td></tr>


<tr><th>X</th>
<tr><th>X</th>
<td>Tenths of a second</td></tr>
<td>Tenths of a second.</td></tr>


<tr><th>XX</th>
<tr><th>XX</th>
<td>Hundredths of a second</td></tr>
<td>Hundredths of a second.</td></tr>


<tr><th>XXX</th>
<tr><th>XXX</th>
<td>Thousandths of a second (milliseconds)</td></tr>
<td>Thousandths of a second (milliseconds).</td></tr>


<tr><th>AM</th>
<tr><th>AM</th>
<td>AM/PM indicator</td></tr>
<td>AM/PM indicator.</td></tr>


<tr><th>PM</th>
<tr><th>PM</th>
<td>AM/PM indicator</td></tr>
<td>AM/PM indicator.</td></tr>
</table>
</table>
   
   
The valid separators in a date format are:
The valid separators in a date format are:
<ul>
<ul>
<li>blank (" ")
<li>blank  
<li>apostrophe ("'")
<li>apostrophe (<b>'</b>)
<li>slash ("/")
<li>slash (<b>/</b>)
<li>colon (":")
<li>colon (<b>:</b>)
<li>hyphen ("-")
<li>hyphen (<b>-</b>)
<li>back slash ("\")
<li>back slash (<b>\</b>)
<li>period (".")
<li>period (<b>.</b>)
<li>comma (",")
<li>comma (<b>,</b>)
<li>underscore ("_")
<li>underscore (<b>_</b>)
<li>left parenthesis ("(")
<li>left parenthesis (<b> ( </b>)
<li>right parenthesis (")")
<li>right parenthesis (<b> ) </b>)
<li>plus ("+")
<li>plus (<b>+</b>)
<li>vertical bar ("|")
<li>vertical bar (<b>|</b>)
<li>equals ("=")
<li>equal (<b>=</b>)
<li>ampersand ("&")
<li>ampersand (<b>&</b>)
<li>at sign ("@")
<li>at sign (<b>@</b>)
<li>sharp ("#")
<li>sharp (<b>#</b>)
<li>the decimal digits ("0" - "9").
<li>the decimal digits (<b>0</b> - <b>9</b>).
</ul>
</ul>
In addition, any character may be a separator character if preceded by
In addition, any character may be a separator character if preceded by
the quoting character (").
the quoting character (<b>"</b>).


==Valid datetimes==
==Valid datetimes==
Line 267: Line 271:


<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 class="note">
<p class="note">
'''Note:''' weekdays are not checked for consistency against the date.
'''Note:''' weekdays are not checked for consistency against the date.
Line 276: Line 281:


<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 YY format can only represent
A datetime string used with a <var>CYY</var> or <var>ZYY</var> format can only represent dates from 1900 to 2899, inclusive.
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>


Line 285: Line 291:
A date field with only two digits for the year value is capable of representing a range of up to one hundred years.
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
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".
thinking of the century as fixed, so that all dates are either <code>19xx</code> or <code>20xx</code>.
However, a date field with two-digit year values can actually represent
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.
dates from two different centuries, provided that the ''range'' of dates does not exceed 100 years.


===Using CENTSPAN===
===Using CENTSPAN===
<var>CENTSPAN</var> provides a mechanism for unambiguously converting dates with
<var>CENTSPAN</var> provides a mechanism for unambiguously converting dates with
two-digit year values into dates with four-digit year values.
two-digit year values into dates with four-digit year values.
Line 304: Line 309:
The effective <var>CENTSPAN</var> value is formed by adding the relative <var>CENTSPAN</var> to the
The effective <var>CENTSPAN</var> value is formed by adding the relative <var>CENTSPAN</var> to the
current four-digit year value at the time the relative value is converted.
current four-digit year value at the time the relative value is converted.
<center>
<p class="figure">
[[File:Centspan.jpg|border|450px]]
[[File:Centspan.jpg|border|450px]]
</center>
</p>


A simple algorithm is used to convert a two-digit year value (YY) to a
A simple algorithm is used to convert a two-digit year value (YY) to a
Line 322: Line 327:
as 1947, when it could have conceivably been 2047.
as 1947, when it could have conceivably been 2047.
Simlarly, the date "46" will be intepreted as 2046, when it might have been 1946.
Simlarly, the date "46" will be intepreted as 2046, when it might have been 1946.
<center>
<p class="figure">
[[File:Spam1.jpg|border|300px]]
[[File:Spam1.jpg|border|300px]]
</center>
</p>


If <var>CENTSPAN</var> is set to a value that is too high, dates that are just prior to <var>CENTSPAN</var> will appear to occur 100 years hence.
If <var>CENTSPAN</var> is set to a value that is too high, dates that are just prior to <var>CENTSPAN</var> will appear to occur 100 years hence.
Line 333: Line 338:


===Using SPANSIZE===
===Using SPANSIZE===
To protect from the ambiguities that
Sirius has devised a method to protect from the ambiguities that
can occur at each end of the 100-year window defined by <var>CENTSPAN</var>,
can occur at each end of the 100-year window defined by <var>CENTSPAN</var>.
<var>SPANSIZE</var> is used to restrict the size of the window used for mapping two-digit year values.
<var>SPANSIZE</var> 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
The effect is to create two ''guard bands''', one just below the
Line 346: Line 350:
for two ten-year windows: one below the <var>CENTSPAN</var> setting and one starting at <code>CENTSPAN+90</code>.
for two ten-year windows: one below the <var>CENTSPAN</var> setting and one starting at <code>CENTSPAN+90</code>.
From our previous example:
From our previous example:
<center>
<p class="figure">
[[File:Spam2.jpg|border|300px]]
[[File:Spam2.jpg|border|300px]]
</center>
</p>


An attempt to represent the values "37" through "46" will be rejected.
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.
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.
Note that an intended value of 2047, expressed as "47" will be accepted and interpreted as 1947.
Line 358: Line 362:


==Strict and non-strict format matching==
==Strict and non-strict 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;
As mentioned above, 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".
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
However, non-strict functions sometimes allow a string to match a token on input that would not be produced by that token on output.
on output.


The types of strict matching are as follows:
The types of strict matching are as follows:
<table class="syntaxTable">
<table class="thJustBold">
<tr><th nowrap>Alpha tokens</th>
<tr><th nowrap>Alpha tokens</th>
<td>For alphabetic tokens (for example, <code>Month</code>), 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 alpabetic tokens are matched by any combination of uppercase and lowercase input.</td></tr>
<td>For alphabetic tokens (for example, <code>Month</code>), 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 alpabetic tokens are matched by any combination of uppercase and lowercase input.</td></tr>
<tr><th>HH, MM, DD</th>
<tr><th>HH, MM, DD</th>
<td>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.</td></tr>
<td>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.</td></tr>
<tr><th>BH, BM, BD</th>
<tr><th>BH, BM, BD</th>
<td>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.</td></tr>
<td>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.</td></tr>
<tr><th>DAY</th>
<tr><th>DAY</th>
<td>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.</td></tr>
<td>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.</td></tr>
<tr><th>ZYY</th>
<tr><th>ZYY</th>
<td>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.</td></tr>
<td>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.</td></tr>
</table>
</table>
Since the strict functions are only available in the <var class="product">[http://m204wiki.rocketsoftware.com/images/d/d6/Ul2krNew.pdf Sir2000 User Language Tools]</var>, if
 
you want to check a datetime string using strict rules, you can use the following technique with the non-strict date functions:
Since the strict functions are only available in the <var class="product">[[Media:Ul2krNew.pdf Sir2000 User Language Tools]]</var>, if you want to check a datetime string using strict rules, you can use the following technique with the non-strict date functions:
<p class="code">if <date> eq '' or
<p class="code">if <date> eq '' or
   <date> ne <date>:stringToMilliseconds(<format>):millisecondsToString(<format>) then
   <date> ne <date>:stringToMilliseconds(<format>):millisecondsToString(<format>) then
Line 386: Line 392:


==Datetime and format examples==
==Datetime and format examples==
The extensive set of format tokens is shown in [[Datetime string formats#Datetime formats|"Datetime formats"]].
The extensive set of format tokens is shown in [[Datetime string formats#Datetime formats|Datetime formats]].
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 398: Line 404:
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.
<table>
 
<table class="thJustBold">
<tr><th>YYMMDD</th>
<tr><th>YYMMDD</th>
<td>This is the common six-digit date format which supports sort order
<td>This is the common six-digit date format which supports sort order
Line 461: Line 468:
<blockquote class="note"><b>Note: </b>
<blockquote class="note"><b>Note: </b>
<ul>
<ul>
<li>If an input format contains <code>AM</code> or <code>PM</code>, then the time (<var class="term">HH:MI</var>)
<li>If an input format contains <code>AM</code> or <code>PM</code>, then the time (<var>HH:MI</var>)
must be between 00:01 and 12:00, and it must be accompanied by either <code>AM</code> or <code>PM</code>.
must be between 00:01 and 12:00, and it must be accompanied by either <var>AM</var> or <var>PM</var>.
<li>If an input format contains <code>DAY</code> (for example, <code>DAY MON YY</code>) with
 
<li>If an input format contains <var>DAY</var> (for example, <var>DAY MON YY</var>) with
non-strict format matching, such as <var>$Sir_Date2nd</var>,
non-strict format matching, such as <var>$Sir_Date2nd</var>,
the string matching it may have a leading zero, thus allowing <code>06 MAY 98</code>.
the string matching it may have a leading zero, thus allowing <code>06 MAY 98</code>.
With strict matching $functions (that is, one of the <var class="product">Sir2000 User Language Tools Functions</var>)
With strict matching $functions (that is, one of the <var class="product">Sir2000 User Language Tools Functions</var>)
however, such a leading zero is not allowed for <code>DAY</code>;
however, such a leading zero is not allowed for <var>DAY</var>;
a single digit must be supplied for days 1 through 9.
a single digit must be supplied for days 1 through 9.
<li>If an input format contains <var class="term">HH</var> with
 
<li>If an input format contains <var>HH</var> with
non-strict format matching, such as <var>$Sir_Date2nd</var>,
non-strict format matching, such as <var>$Sir_Date2nd</var>,
the string that matches it may have a leading blank,
the string that matches it may have a leading blank,
thus allowing " 8:30".
thus allowing " 8:30".
With strict matching, however, such a leading blank is not allowed for <var class="term">HH</var>;
With strict matching, however, such a leading blank is not allowed for <var>HH</var>;
a leading blank hour value with a strict $function
a leading blank hour value with a strict $function
(that is, one of the <var class="product">Sir2000 User Language Tools Functions</var>) requires the <var class="term">BH</var> token.
(that is, one of the <var class="product">Sir2000 User Language Tools Functions</var>) requires the <var>BH</var> token.
If the data contains leading zero hours in some
If the data contains leading zero hours in some
instances and leading blanks in others, you must use a non-strict $function.
instances and leading blanks in others, you must use a non-strict $function.
Line 491: Line 500:
When a pair of format strings are used for transforming date values,
When a pair of format strings are used for transforming date values,
for example for <var>$Sir_Datecnv</var> or processing of updates to <var>SIRFIELD RELATE</var> fields,
for example for <var>$Sir_Datecnv</var> or processing of updates to <var>SIRFIELD RELATE</var> fields,
both formats must have the same number of <var class="term">I</var> tokens.
both formats must have the same number of <var>I</var> tokens.
The $functions with both an input and output format, for example <var>$Sir_Datecnv</var>,
The $functions with both an input and output format, for example <var>$Sir_Datecnv</var>,
are only available in the <var class="product">Sir2000 User Language Tools</var>;
are only available in the <var class="product">Sir2000 User Language Tools</var>;
Line 511: Line 520:
<blockquote class="note"><b>Note: </b>
<blockquote class="note"><b>Note: </b>
<ul>
<ul>
<li>At most one occurrence of the asterisk (<code>*</code>) token may appear in a datetime format.
<li>At most one occurrence of the asterisk (<var>*</var>) token may appear in a datetime format.
 
<li>When a pair of format strings are used for transforming date values,
<li>When a pair of format strings are used for transforming date values,
for example for <var>$Sir_Datecnv</var> or processing of updates to <var>SIRFIELD RELATE</var> fields,
for example for <var>$Sir_Datecnv</var> or processing of updates to <var>SIRFIELD RELATE</var> fields,
then if a <code>*</code> token appears in one of the formats,
then if a <var>*</var> token appears in one of the formats,
a <code>*</code> must also appear in the other format.
a <var>*</var> must also appear in the other format.
<p>  
<p>  
The $functions with both an input and output format, for example <var>$Sir_Datecnv</var>,
The $functions with both an input and output format, for example <var>$Sir_Datecnv</var>,
Line 521: Line 531:
<var>SIRFIELD</var> is part of the <var class="product">Sir2000 Field Migration Facility</var>. </p>
<var>SIRFIELD</var> is part of the <var class="product">Sir2000 Field Migration Facility</var>. </p>
</ul>
</ul>
</blockquote>
</blockquote></td></tr>
 
<tr><th>CYYDDD</th>
<tr><th>CYYDDD</th>
<td>This is a compact six-digit date format with explicit century information, from 1900 through and including 2899.
<td>This is a compact six-digit date format with explicit century information, from 1900 through and including 2899.
Line 531: Line 542:
   
   
<tr><th>ZYYMMDD</th>
<tr><th>ZYYMMDD</th>
<td>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.
<td>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" <var>YYMMDD</var> date values in the 1900s.
The following <var class="product">SOUL</var> fragment prints the values <code>OK</code> and <code>OK</code>:
The following <var class="product">SOUL</var> fragment prints the values <code>OK</code> and <code>OK</code>:
<p class="code">* Check 1 Dec, 1997:
<p class="code">* Check 1 Dec, 1997:
Line 547: Line 558:
thus allowing "0971201".
thus allowing "0971201".
With strict matching, however, a three-digit value with a leading zero
With strict matching, however, a three-digit value with a leading zero
is not allowed for <var class="term">ZYY</var>;
is not allowed for <var>ZYY</var>;
a three-digit value less than 100 with a strict $function
a three-digit value less than 100 with a strict $function
(that is, one of the <var class="product">Sir2000 User Language Tools Functions</var>) requires the <var class="term">CYY</var> token.
(that is, one of the <var class="product">Sir2000 User Language Tools Functions</var>) requires the <var>CYY</var> token.
If the data contains values less than 100 as three digits in some
If the data contains values less than 100 as three digits in some
instances and as two digits in others, you must use a non-strict $function.
instances and as two digits in others, you must use a non-strict $function.
Line 563: Line 574:
Numeric separators, unlike alphabetic separators, do not
Numeric separators, unlike alphabetic separators, do not
need to be preceeded by a double-quote character (<tt>"</tt>). </p>
need to be preceeded by a double-quote character (<tt>"</tt>). </p>
</td></tr>
</table>
</table>


Line 569: Line 581:
any of the following errors can occur:
any of the following errors can occur:
<ul>
<ul>
<li>invalid datetime format specification
<li>Invalid datetime format specification
<li>datetime string not matching format
<li>Datetime string not matching format
<li>datetime out of range for the format
<li>Datetime out of range for the format
<li>invalid <var>CENTSPAN</var> value
<li>Invalid <var>CENTSPAN</var> value
<li>datetime out of range for <var>CENTSPAN</var>/<var>SPANSIZE</var> combination
<li>Datetime out of range for <var>CENTSPAN</var>/<var>SPANSIZE</var> combination
</ul>
</ul>
   
   
Line 582: Line 594:
<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 $functions, respectively.
-9.E12 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
Line 623: Line 636:
   
   
<var class="product">Rocket M204</var> takes
<var class="product">Rocket M204</var> takes
a different approach to the default: a 100 year
a different approach to the default: a 100-year period is used.
period is used.
See the <var class="product">Rocket M204</var> documentation for a
See the <var class="product">Rocket M204</var> documentation for a
description of the CENTSPLT and DEFCENT parameters and $function arguments.
description of the <var>CENTSPLT</var> and <var>DEFCENT</var> parameters and $function arguments.
   
   
==Other $functions using date values==
==Other $functions using date values==
Line 636: Line 648:
<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 646: Line 660:
<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 653: Line 668:
<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>



Revision as of 22:37, 18 September 2015

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 tokens (for example, YYYY for a four-digit year, and MI for minutes) and separator characters (for example, / 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 throughout all Sirius functions, 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 products.

There are certain rules 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.
  • You must specify at least one time, weekday, or date.
  • 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 can not 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.
  • The maximum length of a format string is 100 characters.

Note: A common mistake is to use MM for minutes; it should be MI.

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. The input format rules which convert a value from a DATETIME field are less strict; for example, all of the tokens that convert 'from' an alphabetic string (for example, MON) properly convert a value of the field that contains any case string (for example, jan or JAN or Jan).

In general, the output format rule for a token is shown, that is, the result when a DATETIME or SMALLDATETIME numeric value is converted to a datetime character string in a SOUL %variable. The input format rules for $functions are less strict; for example, all of the tokens which convert 'from' an alpabetic string (for example, MON) will allow any case string (for example, jan or JAN or Jan).

All of the tokens that match alpabetic strings (for example, MON) match any case string (for example, jan or JAN or Jan).

In general, the output format rule for a token is shown. 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. All other tokens that have differing strict and non-strict matching rules are listed under "Special date format rules" in the index at the back of the product manual, and usage notes for them are contained 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.

* 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 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 methods and $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.
MONTH Full month name (uppercase variable length). When 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). When 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). When 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). When 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. When 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.
BM Two-character month number. When 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
DDTwo-digit day number. When 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. When used as an argument to a function for converting from a string, this is the same as DD. 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.
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). When 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). When 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). When 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).

When 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. When 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. When used as an argument to a function for converting from a string, this is the same as HH. 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.
MI Two-digit minute number.
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.

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 (").

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 and Friday, 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. 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 thru 31 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 our previous example, the date "47" will be intepreted as 1947, when it could have conceivably been 2047. Simlarly, the date "46" will be intepreted 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 our 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, 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 alpabetic 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.

Since the strict functions are only available in the Media:Ul2krNew.pdf Sir2000 User Language Tools, if you want to check a datetime string using strict rules, you can use the following technique with the non-strict date 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 in Datetime formats. 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 with the Sirius Functions differs from that with other Sirius products.

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.

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

If $sir_date2nd('960229', 'YYMMDD') > -9E12 Then Print 'OK' End If

YYYYMMDD This is the common eight-digit date format that supports sort order

with dates in two centuries. The following SOUL code fragment prints the value 19921212.

%n = $sir_date2nd('921212', 'YYMMDD') Print $sir_nd2date(%n, 'YYYYMMDD')

MM/DD/YY This is the U.S. six-digit date format for display.

The following SOUL code fragment prints the value OK.

If $sir_date2nd('12/14/94', 'MM/DD/YY') > -9E12 Then Print 'OK' End If

Note:

With non-strict format matching, such as $Sir_Date2nd, the leading zero corresponding to an MM token may be given as a blank, thus allowing " 7/15/98". With strict matching, however, such a leading blank is not allowed for MM; a leading blank month value with a strict $function (that is, one of the Sir2000 User Language Tools Functions) requires the BM token. If the data contains leading zeroes in some month instances and leading blanks in others, you must use a non-strict $function.

DD.MM.YY This is a European six-digit date format for display.

The following SOUL code fragment prints the value OK.

If $sir_date2nd('14.12.94', 'DD.MM.YY') > -9E12 Then Print 'OK' End If

Note:

With non-strict format matching, such as $Sir_Date2nd, the leading zero corresponding to a DD token may be given as a blank, thus allowing " 1.01.00". With strict matching, however, such a leading blank is not allowed for DD; a leading blank day value with a strict $function (that is, one of the Sir2000 User Language Tools Functions) requires the BD token. If the data contains leading zero days in some instances and leading blanks in others, you must use a non-strict $function.

Wkday, DAY Month YYYY "A"T HH:MI This is a format that could be used for report headers.

The following SOUL code fragment prints a value like Friday, 7February 1998 AT 21:33.

Print $sir_date('Wkday, DAY Month YYYY "A"T HH:MI')

Note:

  • If an input format contains AM or PM, then the time (HH:MI) must be between 00:01 and 12:00, and it must be accompanied by either AM or PM.
  • If an input format contains DAY (for example, DAY MON YY) with non-strict format matching, such as $Sir_Date2nd, the string matching it may have a leading zero, thus allowing 06 MAY 98. With strict matching $functions (that is, one of the Sir2000 User Language Tools Functions) however, such a leading zero is not allowed for DAY; a single digit must be supplied for days 1 through 9.
  • If an input format contains HH with non-strict format matching, such as $Sir_Date2nd, the string that matches it may have a leading blank, thus allowing " 8:30". With strict matching, however, such a leading blank is not allowed for HH; a leading blank hour value with a strict $function (that is, one of the Sir2000 User Language Tools Functions) requires the BH token. If the data contains leading zero hours in some instances and leading blanks in others, you must use a non-strict $function.
YYIIII This is a format which could be used for data that contains a two-digit year prefixing other information, such as a sequence number.

The following SOUL code fragment prints the value 02:

%d = $sir_date2nd('92ABCD', 'YYIIII') Print $sir_nd2date(%d + 10*365.25, 'YY')

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 is a format that could 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 following SOUL code fragment prints the values OK and OK.

If $sir_date2nd('92', 'YY*') > -9E12 Then Print 'OK' End If IF $sir_date2nd('1992ABC', 'YYYY*') > -9E12 THEN Print 'OK' End If

Note:

  • At most one occurrence of the asterisk (*) token may appear in a datetime format.
  • 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, then if a * token appears in one of the formats, a * must also appear in the other format.

    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.

CYYDDD This is a compact six-digit date format with explicit century information, from 1900 through and including 2899.

The following SOUL fragment prints the value OK:

If $sir_date2nd('097031', 'CYYDDD') > -9E12 Then Print 'OK' End If

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 following SOUL fragment prints the values OK and OK:

* 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

Note: With non-strict format matching (such as $Sir_Date2nd), a three-digit number with a leading zero may correspond to a ZYY token, thus allowing "0971201". With strict matching, however, a three-digit value with a leading zero is not allowed for ZYY; a three-digit value less than 100 with a strict $function (that is, one of the Sir2000 User Language Tools Functions) requires the CYY token. If the data contains values less than 100 as three digits in some instances and as two digits in others, you must use a non-strict $function.

YY0000 Decimal digits can be used as separator characters.

The following SOUL fragment prints the value 1992NA:

%n = $sir_date2nd('92000', 'YY000') Print $sir_nd2date(%n, 'YYYY"N"A')

Note: Numeric separators, unlike alphabetic separators, do not need to be preceeded by a double-quote character (").

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:

  1. $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.
  2. $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 $functions and all Sirius datetime $functions; in addition, all Sirius 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.

See the Sir2000 User Language Tools manual for a discussion of the error control features it provides.

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

Rocket M204 takes a different approach to the default: a 100-year period is used. See the Rocket M204 documentation for a description of the CENTSPLT and DEFCENT parameters and $function arguments.

Other $functions using date values

In addition to the Sirius datetime functions, which deal only with datetime $functions, there are some $functions that deal with dates from Model 204 internal structures. These $functions and any date processing considerations are:

$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.
  • The last-modified date is retrieved as a two-digit year; to retrieve it as a four-digit year, use $Proc_List or $Proc_ListG.
  • You may sort the $list using a two-digit year if you use the C modifier of $ListSrt.
  • The fourth argument, which specifies the last-modified date selection criterion, is passed as a two-digit year, using a CENTSPAN of 1975.
$Proc_List or $Proc_ListG These $functions retrieve a $list of information about procedures in file/group.
  • The last-modified date is retrieved as a four-digit year.
  • The fourth argument, which specifies the last-modified date selection criterion, is passed as a two-digit year, using a CENTSPAN of 1975.
$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 Sirius datetime processing

Following is a list of benefits offered by Sirius datetime processing. To provide concrete comparisons, there are some references to the standard Model 204 date $functions provided by Rocket M204.

SPANSIZE The SPANSIZE processing creates a very strong barrier to detecting otherwise unnoticed two-digit year processing errors. This is unique to Sirius datetime processing.
Relative CENTSPAN The relative CENTSPAN specification (for example, "-50") let 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 Sirius datetime formats. For example, there are four different tokens representing the day of the week, and time of day can be represented. Rocket M204 date formats do not have any day-of-week nor time-of-day tokens, and other Rocket M204 token variations, for example, CYY vs. ZYY, is done by a complex argument setting.
Pattern match tokens The Sirius 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 imbedded 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 User Language, especially allowing you to add datetime differences (for example, +), rather than calling a DATECHG $function and providing a format.
Time All Sirius datetime $functions allow any reference to a "date" to include time of day. The only Rocket M204 datetime $function that provides a time of day is $TIME, the current time of day, in one fixed format.
$Sir_Date formats $Sir_Date allows you to specify any format to return the current date and time; $DATE has only a few numeric codes for a few formats.
Error control args The Sir2000 User Language Tools provides error handling control that applies to all datetime $functions — Sirius and Rocket M204. Additionally, all Sirius datetime $functions (except $Sir_DateFmt, of course) allow you to specify it 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.