Operator Type:
Operator Scope of Action:
Operator Purpose:
Data Type Returned:
Operator First Added:
Operator in Current Baseline:
Operator Last Altered:
Function [other Function type actions]
Item [operators of similar scope]
Date-time [other Date-time operators]
Date [about Date data type]
v4.0.0
Baseline
As at baseline
date(dateStr)
This constructs a Date-type object from a quoted string or string expression. Note there is an alternate method for specifying a date using the discrete elements (year, month, etc.), see here.
Originally, this is not necessary and Tinderbox would coerce the bare dateStr to a Date-type automatically. This can still happen but best practice, now action code is more complex, is to be more explicit as to intent by using the date() operator. (See format() and .format() to convert dates into strings).
Note that in the examples below, whilst the date() operator creates Date-type data, the examples below are actually coercing it back into a string. As formatting is locale dependent and as aTbRef is written using a UK locale (en-GB), the examples below use day-month order. Thus should be correct for most of the world except the USA and the Philippines where moth-day order is used and where readers will need to transpose the month and day segments of the example output. The action code shown is being exported via ^value()^.
Note that the seconds element of stored Date data is ignored (from v5 onwards). Thus, if present in the Date, seconds are not used and instead are coerced to '00'.
Default: using $MyDate = date("24/10/2009"); will set $MyDate to a "24 Oct 2009 at 22:35:25" (24 October 2009). If no time is supplied hh:mm:ss are set at current system time when $MyDate is set. In the example here, the equivalent date is set on the fly via ^value()^ so the time is the system time as at exporting the note to HTML. The resulting string is the same as you see for a date displayed as a Displayed Attribute. The exact format will depend on the users international settings—also see Document Settings ▸ Displayed Attributes date format.
Now, as above but providing an explicit time element, omitting seconds: $MyDate = date("24/10/2009 01:30:22") gives $MyDate a value of "24 Oct 2009 at 01:30:00"; the specified time gets used, with the seconds added in as per the system clock. If providing a full hh:mm:ss string this is honoured.
But, if you use a date formatting string, you get a formatted string of the date:
$MyString = date("24/10/2009 01:30:00").format("l");gives $MyString a value of "24/10/2009"
or:
$MyString = date("24/10/2009 01:30:00").format("*");gives $MyString a value of "Sat, 24 Oct 2009 01:30:00 +0100"
The two methods are equivalent, note also the change of format due to use of a date format string.
An attribute can also provide part of the input:
$EndDate = date($StartDate+"7 days");
With care this can be extended. In the following, $MyString is "7 days" and $MyNumber is 7. The outcome is that $MyDateA/B/C are all set to the same date:
$MyDateA = date($MyDate+"7 days");
$MyDateB = date($MyDate+$MyString);
$MyDateC = date($MyDate+($MyNumber+" days")); note the extra parentheses here are optional but suggested
See also—notes linking to here: