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.

dateBetween(date, date, string [from unit list]) date.dateBetween(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.

/* 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 */ now().dateBetween(prop("Date"), "days") /* Output: -6 */ /* Assume now() == June 23, 2022 and Date == December 25, 2022 */ dateBetween(now(),prop("Date"),"months") /* Output: -6 */

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.

Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
A new tool that blends your everyday work apps into one. It’s the all-in-one workspace for you and your team
thomasfrank.notion.site
dateBetween(now(), prop("Birth Date"), "years")
lets( ageDays, dateBetween( now(), prop("Birth Date"), "days" ), ageMonths, dateBetween( now(), prop("Birth Date"), "months" ), ageYears, dateBetween( now(), prop("Birth Date"), "years" ), prop("Name") + " is " + ifs( !ageYears and !ageMonths, ageDays + " day" + ifs(ageDays != 1, "s") + " old", !ageYears, ageMonths + " month" + ifs(ageMonths != 1, "s") + " old", ageYears + " year"+ ifs(ageYears != 1, "s") + " 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:

if – Thomas Frank
thomasjfrank.com
add – Thomas Frank
thomasjfrank.com
smaller – Thomas Frank
thomasjfrank.com
equal – Thomas Frank
thomasjfrank.com
format – Thomas Frank
thomasjfrank.com
About the Author

My name is Thomas Frank, and I'm a Notion-certified writer, YouTuber, and template creator. I've been using Notion since 2018 to organize my personal life and to run my business and YouTube channel. In addition to this formula reference, I've created a free Notion course for beginners and several productivity-focused Notion templates. If you'd like to connect, follow me on Twitter.

🤔 Have an UB Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas

🤔 Have a Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas