TimeDiff

Not available in this language yet.
Not available in this language yet.
TimeDiff( start, finish, unit )
TimeDiff( start, finish, unit )
Not available in this language yet.
TimeDiff( start, finish, unit )

Description

The TimeDiff function returns the time difference between start and finish, expressed in unit units. The difference includes start but excludes finish.

Parameters

Argument Type Definition and Requirements

start

The starting date or timestamp. start must match the type of finish.

finish

The ending date or timestamp. finish must match the type of start.

unit

The type of unit that the difference should be expressed in.

When start and finish are Dates, unit must be one of day or days.

When start and finish are Timestamps, 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

A Number which represents the count of unit units between start and finish.

Examples

The following query demonstrates several time differences:

Not available in this language yet.
Not available in this language yet.
Not available in this language yet.
System.out.println(
    client.query(
        Let(
            "start", Time("1970-01-01T00:00:00+00:00"),
            "finish", Now()
        ).in(
            Arr(
                TimeDiff(Date("1970-01-01"), ToDate(Now()), "days"),
                TimeDiff(Var("start"), Var("finish"), "days"),
                TimeDiff(Var("start"), Var("finish"), "half days"),
                TimeDiff(Var("start"), Var("finish"), "hours"),
                TimeDiff(Var("start"), Var("finish"), "minutes"),
                TimeDiff(Var("start"), Var("finish"), "seconds"),
                TimeDiff(Var("start"), Var("finish"), "milliseconds")
            )
        )
    ).get()
);
client.query(
  q.Let(
    {
      'start': q.Time('1970-01-01T00:00:00+00:00'),
      'finish': q.Now(),
    },
    [
      q.TimeDiff(q.Date('1970-01-01'), q.ToDate(q.Now()), 'days'),
      q.TimeDiff(q.Var('start'), q.Var('finish'), 'days'),
      q.TimeDiff(q.Var('start'), q.Var('finish'), 'half days'),
      q.TimeDiff(q.Var('start'), q.Var('finish'), 'hours'),
      q.TimeDiff(q.Var('start'), q.Var('finish'), 'minutes'),
      q.TimeDiff(q.Var('start'), q.Var('finish'), 'seconds'),
      q.TimeDiff(q.Var('start'), q.Var('finish'), 'milliseconds'),
    ]
  )
)
.then((ret) => console.log(ret))
Not available in this language yet.
println(Await.result(
  client.query(
    Let(
      Seq(
        "start" -> Time("1970-01-01T00:00:00+00:00"),
        "finish" -> Now()
      ),
      Arr(
          TimeDiff(Date("1970-01-01"), ToDate(Now()), "days"),
          TimeDiff(Var("start"), Var("finish"), "days"),
          TimeDiff(Var("start"), Var("finish"), "half days"),
          TimeDiff(Var("start"), Var("finish"), "hours"),
          TimeDiff(Var("start"), Var("finish"), "minutes"),
          TimeDiff(Var("start"), Var("finish"), "seconds"),
          TimeDiff(Var("start"), Var("finish"), "milliseconds")
      )
    )
  ),
  5.seconds
))
[18194, 18194, 36388, 436657, 26199422, 1571965360, 1571965360019]
[ 18194, 18194, 36388, 436657, 26199422, 1571965360, 1571965360019 ]
[18194, 18194, 36388, 436657, 26199422, 1571965360, 1571965360019]

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!