StringToDays (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Template:String:StringToDays subtitle}}
{{Template:String:StringToDays subtitle}}
<var>StringToDays</var> is an [[Intrinsic classes|intrinsic]] function to convert a [[Datetime_string_formats|date/time string]] to days since 1900.
<var>StringToDays</var> is an [[Intrinsic classes|intrinsic]] function to convert a [[Datetime_string_formats|date/time string]] to days since 1900.


==Syntax==
==Syntax==
{{Template:String:StringToDays syntax}}
{{Template:String:StringToDays syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%days</th>
<tr><th>%days</th>
<td>The float variable to receive the computed time since 1900.</td></tr>
<td>The float variable to receive the computed time since 1900.</td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>The input date/time string, which must be in the format specified by <var class="term">format</var>.</td></tr>
<td>The input date/time string, which must be in the format specified by <var class="term">format</var>.</td></tr>
<tr><th>format</th>
<tr><th>format</th>
<td>The format of the date/time string.  See [[Datetime string formats#Datetime Formats|"Datetime formats"]].</td></tr>
<td>The format of the date/time string.  See [[Datetime string formats#Datetime Formats|"Datetime formats"]].</td></tr>
<tr><th><var>CentSpan</var></th>
<tr><th><var>CentSpan</var></th>
<td>The <var>[[Datetime string formats#CENTSPAN|CENTSPAN]]</var> value used, if the <var class="term">format</var> has a two-digit year. The default is specified by the <var class="camel">[[CENTSPAN parameter|CENTSPAN parameter]]</var>. In <var class="product">Sirius Mods</var> 7.9 and later this is a [[Notation conventions for methods#Named parameters|name allowed]] parameter. For versions prior to 7.9, it is a positional parameter.</td/tr>
<td>The <var>[[Datetime string formats#CENTSPAN|CENTSPAN]]</var> value used, if <var class="term">format</var> has a two-digit year. The default is specified by the <var class="camel">[[CENTSPAN parameter|CENTSPAN]]</var> parameter. In <var class="product">Sirius Mods</var> 7.9 and later, this is a [[Notation conventions for methods#Named parameters|name allowed]] parameter. For versions prior to 7.9, it is a positional parameter.</td/tr>
</table>
</table>


Line 20: Line 23:
<ul>
<ul>
<li>If the <var class="term">format</var> is invalid, the request is cancelled.
<li>If the <var class="term">format</var> is invalid, the request is cancelled.
<li>If the date contents of the method object <var class="term">string</var> is invalid, an <var>[[InvalidDateString class|InvalidDateString]]</var> exception is thrown.
<li>If the date contents of the method object <var class="term">string</var> is invalid, an <var>[[InvalidDateString class|InvalidDateString]]</var> exception is thrown.
<li>If the <var>CentSpan</var> value is invalid, the request is canceled.
<li>If the <var>CentSpan</var> value is invalid, the request is canceled.
<li>Values returned by <var>StringToDays</var> can be stored in a BINARY or FLOAT4 field, if you want.
<li>Values returned by <var>StringToDays</var> can be stored in a BINARY or FLOAT4 field, if you want.
<li>Dates prior to 1 January 1900 return a negative number.
<li>Dates prior to 1 January 1900 return a negative number.
<li>The inverse of this function is <var>[[DaysToString (Float function)|DaysToString]]</var>.
<li>The inverse of this function is <var>[[DaysToString (Float function)|DaysToString]]</var>.
</ul>
</ul>

Latest revision as of 22:11, 3 September 2015

Convert string date/time to days since 1900 (String class)

[Introduced in Sirius Mods 7.8]

StringToDays is an intrinsic function to convert a date/time string to days since 1900.

Syntax

%days = string:StringToDays( format, [[CentSpan=] number]) Throws InvalidDateString

Syntax terms

%days The float variable to receive the computed time since 1900.
string The input date/time string, which must be in the format specified by format.
format The format of the date/time string. See "Datetime formats".
CentSpan The CENTSPAN value used, if format has a two-digit year. The default is specified by the CENTSPAN parameter. In Sirius Mods 7.9 and later, this is a name allowed parameter. For versions prior to 7.9, it is a positional parameter.

Usage notes

  • If the format is invalid, the request is cancelled.
  • If the date contents of the method object string is invalid, an InvalidDateString exception is thrown.
  • If the CentSpan value is invalid, the request is canceled.
  • Values returned by StringToDays can be stored in a BINARY or FLOAT4 field, if you want.
  • Dates prior to 1 January 1900 return a negative number.
  • The inverse of this function is DaysToString.

Examples

  1. This statement converts a value from YYYYMMDD format:

    printText {~='20110520':stringToDays('YYYYMMDD')}

    The result is:

    '20110520':stringToDays('YYYYMMDD')=40681

  2. This statement uses StringToDays and DaysToString to convert a value in YYYYMMDD format to the Month DAY, YYYY format:

    printText {~='20110520':stringToDays('YYYYMMDD'):daysToString('Month DAY, YYYY')}

    The result is:

    '20110520':stringToDays('YYYYMMDD'):daysToString('Month DAY, YYYY')=May 20, 2011

See also