On June 27, 2023, I learned...

How to calculate the number of days between two dates in Notion

It’s not the most complicated thing in the world. But it did take me a couple of minutes to get it, and I thought I’d write it down in case I need to remember it in the future.

You start with a Date property in a Notion database.

A new date property in Notion.

What I didn’t know up front is that the Date property can be formatted as a range that contains a start date and an end date. So, at first, I had separate properties for Start Date and End Date and planned to calcluate the difference. Personally, I’d have thought that formatting a date as a range is a setting in “Edit Property” perhaps under “Date Format.” Instead, it’s something you select when entering the date for a database item.

Showing the End Date option in the Date property.
The date becomes a date range when enabling the “End date” option.

To calculate the number of days between the two dates, you need another property. This time, it’s a Formula property.

I named the property “Duration” but it could be “Total Days” or whatever.
Pro tip: Click the icon next to the property name to change it.

Notion will ask you to write the formula when you’ve added the property.

This was the tough part, for me, naturally. Notion provides so many functions that can be used in a formula, and it’s not like I’ve memorized what they are. If you type “f” (or whatever) in the “Type a formula” field, though, you can browse what’s available.

I found exactly what I needed: the dateBetween formula!

Selecting the dateBetween function in a Notion formula property.

Looking at the syntax and examples right there in Notion, I knew I’d need:

  • The dateBetween() function
  • The Start date
  • The End date
  • The units to measure in (e.g. days, weeks, months, etc.)

The dates live in the “Dates” property that was set up first. So, let’s plug those in to the dateBetween() formula. Notion says this is the syntax for counting the days between two dates:

dateBetween(date, date2, "days")

The problem for me was that I wasn’t sure how to indicate the two dates because the Dates property is technically one property. How the heck do you differentiate beween the two?

dateBetween(prop("Dates"), prop("Dates"), "days")

Turns out it’s pretty simple: there are two additional functions we can use to extract the start and end dates separately: start() and end():

dateBetween(end()), start(), "days")

Pluggin in the dates, then, looks like this:

dateBetween(end(prop("Dates")), start(prop("Dates")), "days")

And that, my friends, calculates the number of days between the start date and end date in Notion’s Date property.

Leave a Reply

Markdown supported