add_time

Modified on Thu, 9 Jul at 10:49 AM

add_time

TABLE OF CONTENTS

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

Input
{
  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')
}
Output
{
  "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".

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article