TimeSubtract

Not available in this language yet.
Not available in this language yet.
TimeSubtract( base, offset, unit )
TimeSubtract( base, offset, unit )
Not available in this language yet.
TimeSubtract( 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:

Not available in this language, yet.
Not available in this language, yet.
System.out.println(
    client.query(
        TimeSubtract(Epoch(1, "day"), 1, "second")
    ).get());
1970-01-01T23:59:59Z
client.query(
  q.TimeSubtract(q.Epoch(1, 'day'), 1, 'second')
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
Time("1970-01-01T23:59:59Z")
Not available in this language, yet.
try {
  println(Await.result(
  client.query(
    TimeSubtract(Epoch(1, "day"), 1, "second")
  ),
  5.seconds
))} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
1970-01-01T23:59:59Z

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

Not available in this language, yet.
Not available in this language, yet.
System.out.println(
    client.query(
        Arr(
            Time("2020-07-06T12:34:56.789Z"),
            TimeSubtract(Time("2020-07-06T12:34:56.789Z"), 5, "seconds")
        )
    ).get());
[2020-07-06T12:34:56.789Z, 2020-07-06T12:34:51.789Z]
client.query([
  q.Now(),
  q.TimeSubtract(q.Now(), 5, 'seconds'),
])
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
[ Time("2019-10-22T16:45:19.755048Z"),
  Time("2019-10-22T16:45:14.755048Z") ]
Not available in this language, yet.
try {
  println(Await.result(
  client.query(
    Arr(
      Time("2020-07-06T12:34:56.789Z"),
      TimeSubtract(Time("2020-07-06T12:34:56.789Z"), 5, "seconds")
    )
  ),
  5.seconds
))} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
[2020-07-06T12:34:56.789Z, 2020-07-06T12:34:51.789Z]

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

Not available in this language, yet.
Not available in this language, yet.
System.out.println(
    client.query(
        TimeSubtract(Date("2019-11-26"), 1, "day")
    ).get());
2019-11-25
client.query(
  q.TimeSubtract(q.Date('2019-11-26'), 1, 'day')
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
Date("2019-11-25")
Not available in this language, yet.
try {
  println(Await.result(
  client.query(
    TimeSubtract(Date("2019-11-26"), 1, "day")
  ),
  5.seconds
))} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
2019-11-25

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!