# dateBetween

Learn how to use the dateBetween function in Notion formulas.
The `dateBetween()` function returns the amount of time between two dates, based on a specified unit of time.
1
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

1
// Assume now() == June 23, 2022 and Date == June 1, 2022
2
dateBetween(now(),prop("Date"),"days") // Output: 22
3
4
// Assume now() == June 23, 2022 and Date == June 30, 2022
5
dateBetween(now(),prop("Date"),"days") // Output: -6
6
7
// Assume now() == June 23, 2022 and Date == December 25, 2022
8
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.

### "Age" Property Formula

1
dateBetween(now(), prop("Birth Date"), "years")

### "Age (Pretty)" Property Formula

1
// Compressed
2
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."))
3
4
// Expanded
5
prop("Name") + " is " +
6
if(
7
dateBetween(
8
now(),
9
prop("Birth Date"),
10
"years"
11
) < 1,
12
format(
13
dateBetween(
14
now(),
15
prop("Birth Date"),
16
"months"
17
)
18
) + if(
19
dateBetween(
20
now(),
21
prop("Birth Date"),
22
"months"
23
) == 1,
24
" month old.",
25
" months old."
26
),
27
format(
28
dateBetween(
29
now(),
30
prop("Birth Date"),
31
"years"
32
)
33
) + if(
34
dateBetween(
35
now(),
36
prop("Birth Date"),
37
"years"
38
) == 1,
39
" year old.",
40
" years old."
41
)
42
)
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".