dateSubtract

Learn how to use the dateSubtract function in Notion formulas.
The `dateSubtract()` function accepts a date argument and subtracts from it, returning a new date.
1
dateSubtract(date, number, string [from unit list])
It requires three arguments in the following order:
1. 1.
A date (must be an actual date data type)
2. 2.
A number
3. 3.
A unit
Accepted units include:
• “years”
• “quarters”
• “months”
• “weeks”
• “days”
• “hours”
• “minutes”
• “seconds”
• “milliseconds”

Example Formulas

1
// Assume a property called "Date" with a current row value
2
// of June 1, 2022
3
dateSubtract(prop("Date"),3,"months") // Output: March 1, 2022
4
5
dateSubtract(prop("Date"),5,"days") // Output: May 27, 2022
You can nest multiple `dateSubtract()` functions to subtract multiple different types of units from a date:
1
// Assume a property called "Date" with a current row value
2
// of June 1, 2022
3
dateSubtract(dateSubtract(prop("Date"),3,"months"),5,"days")
4
// Output: February 24, 2022
`dateSubtract()` accepts negative values:
1
// Assume a property called "Date" with a current row value
2
// of June 1, 2022
3
dateSubtract(prop("Date"), -3, "months") // Output: September 1, 2022

Example Database

This example database demonstrates how to output a date object set to January 1, 12:00 AM in the current year, in your current time zone.

"Jan 1" Property Formula

1
// Compressed
2
dateSubtract(dateSubtract(dateSubtract(dateSubtract(now(), minute(now()), "minutes"), hour(now()), "hours"), date(now()) - 1, "days"), month(now()), "months")
3
4
// Expanded
5
dateSubtract(
6
dateSubtract(
7
dateSubtract(
8
dateSubtract(
9
now(),
10
minute(
11
now()
12
),
13
"minutes"
14
),
15
hour(
16
now()
17
),
18
"hours"
19
),
20
date(
21
now()
22
) - 1,
23
"days"
24
),
25
month(
26
now()
27
),
28
"months"
29
)
This formula uses multiple instances of `dateSubtract()` to remove different units of time from the output of the now function in order to arrive at Jan 1, 12:00 AM.
The amount of time that is subtracted from `now()` is actually derived from `now()` itself. For example:
1
dateSubtract(
2
now(),
3
minute(
4
now()
5
),
6
"minutes"
7
)
Here, `minute(now())` gets the minute value from `now()`.
So, if it's currently 3:12 PM, this essentially says:
Subtract 12 minutes from 3:12 PM.
The resulting output would be 3:00 PM.
The formula then takes this output and does the same thing using hour, date, and month.
The only caveat is that `1` must be substracted from the output of `date()`, since there is no "January 0".