TimeAdd

TimeAdd( base, offset, unit )

Description

The TimeAdd function increases a base Timestamp or Date by adding the offset in units.

Parameters

Argument Type Definition and Requirements

base

A timestamp or date to add to. base must match the type of unit.

offset

The number of units to add to base.

unit

The offset's unit.

When base is a Date, unit must be one of day or days.

When base is a Timestamp, unit must be one of:

  • day, or days

  • half day, or half days

  • hour, or hours

  • minute, or minutes

  • second, or seconds

  • millisecond, or milliseconds

  • microsecond, or microseconds

  • nanosecond, or nanoseconds

Returns

When base is a Date, a new Date which represents base with offset units added to it.

When base is a Timestamp, a new Timestamp which represents base with offset units added to it.

Examples

The following query returns a Timestamp representing one day after the Unix epoch:

client.query(
  q.TimeAdd(q.Epoch(0, 'second'), 1, 'day')
)
.then((ret) => console.log(ret))
Time("1970-01-02T00:00:00Z")

The following query returns a Timestamp 5 seconds in the future from now:

client.query([
  q.Now(),
  q.TimeAdd(q.Now(), 5, 'seconds'),
])
.then((ret) => console.log(ret))
[ Time("2019-10-22T16:45:19.223863Z"),
  Time("2019-10-22T16:45:24.223863Z") ]

The following query returns a Date 1 day after 2019-11-26:

client.query(
  q.TimeAdd(Date('2019-11-26'), 1, 'day')
)
.then((ret) => console.log(ret))
Date("2019-11-27")

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!