The year()
function returns an integer (number) that corresponds to the year of its date argument.
year(date)
Code language: JavaScript (javascript)
year()
(and its sibling functions minute, hour, day, date, and month) is useful for manipulating dates within Notion formulas.
Example Formulas
year(now()) // Output: 2022 (When now() = June 24, 2022)
// Assume a property called Date with a current date of June 24, 2022
year(prop("Date")) // Output: 2022
Code language: JavaScript (javascript)
year()
can be used with other functions such as dateSubtract to change the value of a date, like so:
// Assume the value of now() is June 24, 2022
dateSubtract(now(), 10, "years")
// Output: June 24, 2012
Code language: JavaScript (javascript)
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.
Example Database
The now formula example shows how to “hard-code” a date into a Notion formula without a specific year. The example database below does the same thing, except it allows you to specify a year using a Number property.
View and Duplicate Database
“Date” Property Formula
// Compressed
dateAdd(dateAdd(dateAdd(dateSubtract(dateSubtract(dateSubtract(dateSubtract(dateSubtract(now(), minute(now()), "minutes"), hour(now()), "hours"), date(now()) - 1, "days"), month(now()), "months"), year(now()), "years"), toNumber(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(prop("Month"), "January", "0"), "February", "1"), "March", "2"), "April", "3"), "May", "4"), "June", "5"), "July", "6"), "August", "7"), "September", "8"), "October", "9"), "November", "10"), "December", "11")), "months"), prop("Day") - 1, "days"), prop("Year"), "years")
// Expanded
dateAdd(
dateAdd(
dateAdd(
dateSubtract(
dateSubtract(
dateSubtract(
dateSubtract(
dateSubtract(
now(),
minute(
now()
),
"minutes"
),
hour(
now()
),
"hours"
),
date(
now()
) - 1,
"days"
),
month(
now()
),
"months"
),
year(
now()
),
"years"
),
toNumber(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
prop("Month"),
"January",
"0"
),
"February",
"1"
),
"March",
"2"
),
"April",
"3"
),
"May",
"4"
),
"June",
"5"
),
"July",
"6"
),
"August",
"7"
),
"September",
"8"
),
"October",
"9"
),
"November",
"10"
),
"December",
"11"
)
),
"months"
),
prop("Day")-1,
"days"
),
prop("Year"),
"years"
)
Code language: JavaScript (javascript)
This formula works the same way as the formula in the now article, except we’re now adding one extra instance of dateAdd and dateSubtract. These final instances:
- Use
year()
to take the current year and set it to 0. - Then add the specified year in the Year property.