add_time
Add some amount of time to a given date
Definition
date add_time(date $startDate, number|string $offset, string $offsetType)
Returns a new time after adding $offset
time units offsetType
to $startDate
.
Adds $offset
to $startDate
and returns the new date. $offsetType
can be one of the following values:
- t (ticks)
- ms (milliseconds)
- s (seconds)
- min (minutes)
- h (hours)
- d (days)
- m (months)
- y (years)
Parameters
datetime $startDate
The date to add $offset to.
datetime$offset
The amount of time, positive or negative, in $offsetType to add to $startDate.
datetime$offsetType
The time unit for offset.
Returns
A new datetime with $offset
added to $startDate
.
Examples
{
time1: add_time(current_time(`0`), `4`, 'h'),
time2: add_time(to_datetime('2021-11-25T12:35:26.1497469Z', 'o', 'en-US'), '3', 't'),
time3: format(add_time(to_datetime('2021-02-21 12:00:00Z', 'u', 'da-DK'), `-7`, 'd'), 'd MMM, yyyy', 'en-US')
}
{
"time1": "2021-11-25T16:00:00", // This assumes current time is 2021-11-25T12:00:00
"time2": "2021-11-25T12:35:26.1497472Z",
"time3": "14 Feb, 2021"
}
Remarks
If the final result yields a year before 1 AD or after 9999 AD, a warning is raised and the time returned is "0001-01-01T00:00:00".
Updated about 1 year ago