TimeDiff
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 |
---|---|---|
|
The starting date or timestamp. |
|
|
The ending date or timestamp. |
|
|
The type of unit that the difference should be expressed in. When When
|
Returns
A Number which represents the count of
unit
units between start
and finish
.
Examples
The following query demonstrates several time differences:
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))
[ 18194, 18194, 36388, 436657, 26199422, 1571965360, 1571965360019 ]
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!