date_diff

Gives the time from one timestamp to another in a unit, as a whole number (positive when the second is later). "second", "minute", "hour" and "week" count elapsed time, rounded toward zero. "day" counts calendar days in the app's timezone, the times of day ignored: from 11 pm to 1 am the next day is one day. "month" and "year" count whole calendar months or years passed.

Runs on: either side: the compiler places the statement that calls it where the values it uses live.

Format:

date_diff(from_timestamp, to_timestamp, unit)

Parameters:

Parameter Type Description
from_timestamp number the earlier (or later) UNIX timestamp
to_timestamp number the other timestamp
unit string "second", "minute", "hour", "day", "week", "month" or "year"

Returned Value:

Type Description
number the difference, in whole units

Examples

age = date_diff(person.born_at, today(), "year")