The dateBetween()
function returns the amount of time between two dates, based on a specified unit of time.
dateBetween(date, date, string [from unit list])
The function returns a number, and requires three arguments in the following order:
- Date 1 (must be a date data type)
- Date 2 (must be a date data type)
- A unit
Accepted units include:
- “years”
- “quarters”
- “months”
- “weeks”
- “days”
- “hours”
- “minutes”
- “seconds”
- “milliseconds”
dateBetween()
returns a positive number when the first date is later than the second date.
Good to know: You can use the abs function to ensure the output is always positive.
Example Formula
// Assume now() == June 23, 2022 and Date == June 1, 2022
dateBetween(now(),prop("Date"),"days") // Output: 22
// Assume now() == June 23, 2022 and Date == June 30, 2022
dateBetween(now(),prop("Date"),"days") // Output: -6
// Assume now() == June 23, 2022 and Date == December 25, 2022
dateBetween(now(),prop("Date"),"months") // Output: -6
Example Database
This example database uses the Birth Date property to determine the age of each person. Additional logic is included to deal with plurality (”year” vs “years”), and to express infant age in months.

View and Duplicate Database

“Age” Property Formula
dateBetween(now(), prop("Birth Date"), "years")
“Age (Pretty)” Property Formula
// Compressed
prop("Name") + " is " + if(dateBetween(now(), prop("Birth Date"), "years") < 1, format(dateBetween(now(), prop("Birth Date"), "months")) + if(dateBetween(now(), prop("Birth Date"), "months") == 1, " month old.", " months old."), format(dateBetween(now(), prop("Birth Date"), "years")) + if(dateBetween(now(), prop("Birth Date"), "years") == 1, " year old.", " years old."))
// Expanded
prop("Name") + " is " +
if(
dateBetween(
now(),
prop("Birth Date"),
"years"
) < 1,
format(
dateBetween(
now(),
prop("Birth Date"),
"months"
)
) + if(
dateBetween(
now(),
prop("Birth Date"),
"months"
) == 1,
" month old.",
" months old."
),
format(
dateBetween(
now(),
prop("Birth Date"),
"years"
)
) + if(
dateBetween(
now(),
prop("Birth Date"),
"years"
) == 1,
" year old.",
" years old."
)
)
Here, we create a “pretty” sentence that states the person’s name along with their age.
A nested if-statement is used to determine whether the age meets certain criteria. Depending on the result, the formula will return different ending strings:
- If the person is less than 1 year old, the ending output will be “months old” or “month old” depending on the number of months.
- If the person is exactly 1 year old, the ending output will be “year old.”
- Otherwise, the ending output will be “years old”.
Other formula components used in this example:




