Operator Scope of Action:
Operator First Added:
constructs a Date from a quoted string or string expression. Usually, this is not necessary; Tinderbox will coerce the string to a date type automatically. In some contexts though, it may be more convenient or more clear to make the conversion explicit. (See format() and .format() to convert dates into strings).
This operator creates actual Date-type data, which the examples below are actually coercing back into a string Note too that the examples below were output from a system with UK setting, thus using day-month order. For reference, month-day order is actually only used in the USA and the Philippines whilst the rest of the world uses day-month order, though the delimiters used in text can vary (slash, colon, dot, etc.). The action code shown is being exported via ^value()^.
Note that seconds are ignored (from v5 onwards); if provided they are not used and are coerced to '00' instead.
$MyDate = date("24/10/2009"); sets $MyDate to "24/10/2009, 22:28"; note how the hh:mm current at export get added. 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.
Provide a time:
$MyDate = date("24/10/2009 01:30:22") gives $MyDate a value of "24/10/2009, 01:30"; the specified time gets used.
But, if you a date formatting string and you get a formatted string of the date:
$MyString = date("24/10/2009 01:30:00").format("*"); gives $MyDate a value of "Sat, 24 Oct 2009 01:30:00 +0000
$MyString = date("24/10/2009 01:30:00").format("*"); gives $MyDate a value of "Sat, 24 Oct 2009 01:30:00 +0000"
The two methods are equivalent, note also the change of format due to use of a date format string. In the first example above note how the format() operator wraps date() and not vice versa.
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 are optional but suggested