{timestamp:datetime}

Description

Converts a textual date into a Unix timestamp - the number of seconds since 1970-01-01 00:00:00 UTC. It is a thin wrapper around PHP strtotime, so it understands ISO dates (2008-07-01), full datetime strings (2008-07-01 14:30), compact ISO basic form (20080701t223807), and relative English phrases (today, next Monday, +1 day). The result is the integer you would feed to date-and-time commands such as date, daterange and datediff, all of which expect a Unix timestamp. The parameter is parsed in the server timezone (Europe/Prague on this install). Two traps worth knowing: an empty parameter and any text strtotime cannot parse both return an empty string (not 0), and a bare integer such as 1700000000 is NOT recognised as an already-made timestamp - it returns empty; prefix it with an at-sign, as in @1700000000, to force strtotime to read it as a Unix timestamp. Relative phrases are evaluated against the current clock, so their output changes over time.

Parameters

datetime optional default (empty)

The textual date to convert. Accepts ISO dates (2008-07-01), datetime strings (2008-07-01 14:30), compact ISO basic form (20080701t223807) and relative English phrases (today, next Monday, +1 day). Parsed in the server timezone. A bare integer is not treated as an existing Unix timestamp; prefix it with an at-sign to force that. Unparseable or empty text yields an empty string.

Examples

test{timestamp:2008-07-01}
Expected1214863200
Actual1214863200
An ISO date (no time) becomes the Unix timestamp of midnight on that day in the server timezone.
test{timestamp:2008-07-01 14#:30}
Expected1214915400
Actual1214915400
A full datetime keeps the time of day. Note the escaped colon: a bare colon in any parameter is read as an argument separator, so a time like 14:30 must be written 14#:30 (the AA escaped-colon). The result points at 14:30 local time, not midnight.
test{timestamp:20080701t223807}
Expected1214944687
Actual1214944687
strtotime also reads the compact ISO basic form (YYYYMMDDtHHMMSS): 2008-07-01 at 22:38:07.
test[{timestamp:@1700000000}]
Expected[1700000000]
Actual[1700000000]
An at-sign prefix tells strtotime the value already IS a Unix timestamp, so it is returned unchanged. Brackets only frame the output.
test[{timestamp:1700000000}]
Expected[]
Actual[]
Trap: a plain integer is not recognised as a date or a timestamp and yields an empty string. Use the at-prefix (see the previous example) to pass an existing timestamp.
test[{timestamp:not a date}]
Expected[]
Actual[]
Any text strtotime cannot understand returns an empty string, never 0. Brackets show the output is truly empty.
test[{timestamp:}]
Expected[]
Actual[]
An empty parameter also returns an empty string (it does not default to the current time). Use the now command for the current time.
test{date:Y-m-d:{timestamp:2008-07-01}}
Expected2008-07-01
Actual2008-07-01
The real-world pattern: convert a textual date to a timestamp, then format it with the date command. Here it round-trips back to the same ISO date.
virtual{timestamp:next Monday}
Expected(a Unix timestamp for the upcoming Monday, e.g. 1780869600)
Actual1780869600
Relative English phrases are resolved against the current clock, so the output changes from day to day. Illustrative only - not a fixed value.