date() function returns an integer (number) between
31 that corresponds to the day of the month of its date argument.
date() (and its sibling functions minute, hour, date, month, and year) is useful for manipulating dates within Notion formulas.
date(now()) // Output: 24 (when now() = June 24, 2022) // Assume a property called Date with a current date of June 1, 2022 11:29 AM date(prop("Date")) // Output: 1
date() can be used with other functions such as dateSubtract to change the value of a date.
Here, it is used with dateSubtract and now to return a date at the start of the month.
// Assume the value of now() is June 24, 2022 dateSubtract(now(),date(now())-1,"days") // Output: June 1, 2022
Note that since the lowest integer value of
1, I have to use
date(now())-1 to get the first day of the month.
You can take this concept even further to “hard-code” any date into a Notion formula. See the section on Hard-Coding Dates into Formulas within the now article for more on how to do this.
This example database takes a date from the Date property and returns both the first and last day of the month that contains that date.
View and Duplicate Database
“First Day of Month” Property Formula
// Compressed dateSubtract(prop("Date"), date(prop("Date")) - 1, "days") // Expanded dateSubtract( prop("Date"), date( prop("Date") ) - 1, "days" )
To get the first day of the month, we simple subtract the
date() integer (minus one) of the Date property from the Date property itself. We have to subtract one from the
date() output in order to get to the 1st of the month – there’s no 0th day of the month!
“Last Day of Month” Property
// Compressed dateSubtract(dateAdd(prop("Date"), 1, "months"), date(prop("Date")), "days") // Expanded dateSubtract( dateAdd( prop("Date"), 1, "months" ), date( prop("Date") ), "days" )
The end of the month is a variable number. Some months have 31 days, some have 30, and one has 28… sometimes.
To solve for this, we first use dateAdd to add one month to Date property’s date. Then, we do the exact same
date() subtraction operation described in the “First Day of the Month” section.
However, this time we don’t subtract one from
date()‘s output, as we want to go one day further backwards from the 1st of the month.