If you’ve been knocking around Notion for a while you’ve probably had occasion to dynamically check if an entry date falls within the current week. The use cases for this type of formula are endless, for example, you may want to show only tasks or events for the current week, or maybe you have a habit tracker or food log that benefits from a weekly view. First we’ll explore the problems with one common way this is achieved, then we’ll discover the solution.
The Problem
One common way this is handled is by using the formatDate()
function to get the numerical week number (1-52 for each week of the year) and compare it against the current week number for now()
. If the two match, it is the current week. Adding onto this concept, you can -1 or +1 from now()
to get last week or next week.
This Week
if(formatDate(prop("Date"), "w") == formatDate(now(), "w"), true, false)
Last Week
if(formatDate(prop("Date"), "w") == formatDate(now() - 1, "w"), true, false)
Next Week
if(formatDate(prop("Date"), "w") == formatDate(now() + 1, "w"), true, false)
But this method is not reliable. Here’s why:
The same numeric week from previous or future years would also display.
We can counter this with an additional check to see if the date is also within the current year, and then apply both to a filter:
While this is more accurate, you will still run into problems near the start or the end of the current year if part of the current week falls into a different calendar year. This will prevent some of your dates from displaying accurately.
The Solution
Here is a new solution that is 100% accurate and reliable for determining if a date falls within the current week. We do this by determining the actual start and end dates for the current week using the dateSubtract()
function, then check if the entry date falls within that range.
This Week
if(prop("Date") >= dateSubtract(dateSubtract(dateSubtract(now(), toNumber(formatDate(now(), "d")), "days"), toNumber(formatDate(now(), "H")), "hours"), toNumber(formatDate(now(), "m")), "minutes") and prop("Date") < dateAdd(dateSubtract(dateSubtract(dateSubtract(now(), toNumber(formatDate(now(), "d")), "days"), toNumber(formatDate(now(), "H")), "hours"), toNumber(formatDate(now(), "m")), "minutes"), 7, "days"), true, false)
With some slight modifications we can similarly calculate for last week or next week as well.
Last Week
if(prop("Date") < dateSubtract(dateSubtract(dateSubtract(now(), toNumber(formatDate(now(), "d")), "days"), toNumber(formatDate(now(), "H")), "hours"), toNumber(formatDate(now(), "m")), "minutes") and prop("Date") >= dateSubtract(dateSubtract(dateSubtract(now(), toNumber(formatDate(now(), "d")) + 7, "days"), toNumber(formatDate(now(), "H")), "hours"), toNumber(formatDate(now(), "m")), "minutes"), true, false)
Next Week
if(prop("Date") >= dateAdd(dateSubtract(dateSubtract(dateSubtract(now(), toNumber(formatDate(now(), "d")), "days"), toNumber(formatDate(now(), "H")), "hours"), toNumber(formatDate(now(), "m")), "minutes"), 7, "days") and prop("Date") < dateAdd(dateSubtract(dateSubtract(dateSubtract(now(), toNumber(formatDate(now(), "d")), "days"), toNumber(formatDate(now(), "H")), "hours"), toNumber(formatDate(now(), "m")), "minutes"), 14, "days"), true, false)
Then set your filter to display only entries with the correct dynamic week checked.