TimeSubtract

Copied!
( base, offset, unit )

Description

The TimeSubtract function decreases a base Timestamp or Date by subtracting the offset in units.

Parameters

Argument Type Definition and Requirements

base

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

offset

The number of units to subtract from 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 subtracted from it.

When base is a Timestamp, a new Timestamp which represents base with offset units subtracted from it.

Examples

The following query subtracts 1 second from 1 day after Unix epoch:

Copied!
client.query(
  q.(q.(1, 'day'), 1, 'second')
)
.then((ret) => console.log(ret))
("1970-01-01T23:59:59Z")

The following query returns a Timestamp 5 seconds in the past before now:

Copied!
client.query([
  q.(),
  q.(q.(), 5, 'seconds'),
])
.then((ret) => console.log(ret))
[ ("2019-10-22T16:45:19.755048Z"),
  ("2019-10-22T16:45:14.755048Z") ]

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

Copied!
client.query(
  q.(q.('2019-11-26'), 1, 'day')
)
.then((ret) => console.log(ret))
("2019-11-25")

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!