# equal

Learn how to use the Boolean "equal" (==) operator in Notion formulas.
The equality (`==`) operator returns true if its operands are equal. It accepts operands of all data types - strings, numbers, Booleans, and dates.
1
string == string
2
number == number
3
Boolean == Boolean
4
date == date
5
6
equal(string, string)
7
equal(number, number)
8
equal(Boolean, Boolean)
9
equal(date, date)
Good to know: Notion does not allow for comparisons between different data types, so the strict equality operator `===` is not supported (or rather, the equality operator (`==`) is already a strict equality operator). You must convert all data to a common type before making a comparison (e.g. by using format() to create a string value).
You can also use the function version, `equal()`.

## Example Formulas

1
1 == 1 // Output: True
2
3
equal(1,1) // Output: True
4
5
1 == 2 // Output: False
6
7
"1" == 1 // Type mismatch error
8
9
+"1" == 1 // Output: True (uses the unaryPlus operator to convert "1" to a number
10
11
2^2 == 4 // Output: True
12
13
length("Monkey D. Luffy") == 15 // Output: True
Good to know: The equality (`==`) operator cannot be chained in a Notion formula. A formula like `1 == 1 ==1` won't work. Use the and operator to get around this - e.g. `1 == 1 and 1 == 1`.

## Example Database

The example database below shows several rows with random dates. The Last Weekday property displays the last weekday in that date’s month, and then the Day Name property shows which day of the week it is.

### View and Duplicate Database

Want a simpler example? Check out the one on the inequality (`!=`) operator's page. These operators are opposites, but their usage (and operator precedence) is the same.

### Last Weekday Explanation

To get the last weekday of the month in a Notion formula, we follow this process:
1. 1.
First, obtain the last day of the month:
1. 1.
Add 1 month to the current date in the Date property, using dateAdd().
2. 2.
Subtract `x` days from the resulting date using dateSubtract(), where `x` is that date's date index (E.g. `June 11` would have a date index of `11`)
3. 3.
Since all months start on the 1st, this will always get you to the last day of the preceding month. (e.g. `June 11 - 11 == May 31`).
2. 2.
Next, check if the last day of the month is a Sunday using date(). If so, subtract 2 days from it and output the resulting date, which will be a Friday.
3. 3.
If the last day of the month isn't a Sunday, check if it's a Saturday. If so, subtract 1 day from it and output the resulting date, which will be a Friday.
4. 4.
If the last day of the month isn't a Sunday or Saturday, simply output it.
To keep this example simple and easy to follow, I've created the Last Day property to act as a variable that we can call from the Last Weekday formula.
Good to know: You can't explicitly define variables in a Notion formula, so you'll need to use a separate property for each variable instead.
Finally, the Day Name property uses the formatDate() function to display the actual day of the week that corresponds to Last Weekday's date.

### "Last Weekday" Property Formula

1
// Compressed
2
if(day(prop("Last Day")) == 0, dateSubtract(prop("Last Day"),2,"days"), if(day(prop("Last Day")) == 6, dateSubtract(prop("Last Day"),1,"days"),prop("Last Day")))
3
4
// Expanded and Commented
5
if(
6
7
// Check if the day of the week index for Last Day
8
// is 0 (Sunday).
9
day(
10
prop("Last Day")
11
) == 0,
12
13
// If it is 0, subtract 2 days from Last Day to arrive at the
14
// nearest weekday (Friday).
15
dateSubtract(
16
prop("Last Day"), 2, "days"
17
),
18
19
// If it isn't 0, next check if the day of the week index
20
// for Last Day is 6 (Saturday).
21
if(
22
day(
23
prop("Last Day")
24
) == 6,
25
26
// If it is 6, subtract 1 day from Last Day to arrive at
27
// the nearest weekday (Friday).
28
dateSubtract(
29
prop("Last Day"), 1, "days"
30
),
31
32
// If the day of the week index isn't 0 or 6, output the
33
// Last Day property as-is.
34
prop("Last Day")
35
)
36
)

### "Last Day" Property Formula

1
// Compressed
2
3
4
// Expanded and Commented
5
6
// Get the last day of the current month by adding 1 month to the current Date,
7
// then subtracting the number of days in that date's date() index.
8
dateSubtract(
9
10
// Add 1 month to the current date.
11
// E.g. - May 11 + 1 month == June 11
12
13
prop("Date"), 1, "months"
14
),
15
16
// Get the number of days to be subtracted using the date()
17
// function. E.g. - June 11 == 11
18
date(
19
20
prop("Date"), 1, "months"
21
)
22
),
23
24
// Specify the date unit to be subtracted; in this case, "days"
25
"days"
26
)
If you're curious, here's how you could create a single mega-formula that can find the last weekday of the month without the need for a Last Day variable property:
// Compressed
// Expanded and Commented
if(
// Get the day of the week index for the last day of Date's month,
// and see if it equals 0 (Sunday)
day(
// Output the last day of Date's month, by first
// adding one month to Date, then subtracting that date's
// date() value. Example:
// May 11 + 1 month == June 11
// June 11 - 11 == May 31
dateSubtract(
prop("Date"), 1, "months"
),
date(
prop("Date"),1,"months")
),
"days"
)
) == 0,
// If the day of the week index does match 0 (Sunday), then
// subtract 2 days to get to a weekday (Friday)
dateSubtract(
dateSubtract(
prop("Date"), 1, "months"
),
date(
prop("Date"), 1, "months"
)
),
"days"
),
2,
"days"
),
// If the day of the week index does NOT match 0 (Sunday), next
// check if it matches 6 (Saturday).
if(
day(
dateSubtract(
prop("Date"), 1, "months"
),
date(
prop("Date"), 1, "months"
)
),
"days"
)
) == 6,
// If the day of the week index does match 6 (Saturday),
// subtract 1 day from that date to get to the nearest
// weekday (Friday).
dateSubtract(
dateSubtract(
prop("Date"), 1, "months"
),
date(
prop("Date"), 1, "months"
)
),
"days"
),
1,
"days"
),
// If the day of the week index did not match 0 (Sunday) or
// 6 (Saturday), then output the date as-is.
dateSubtract(
prop("Date"), 1, "months"
),
date(
prop("Date"), 1, "months"
)
),
"days"
)
)
)
If you take the time to read the formula fully, you'll notice that we're just repeating the formula within the Last Day property multiple times - precisely, everythere I called `prop("Last Day")` in the simpler Last Week formula above.
This is the trade-off with Notion formulas; since you can't define variables in a formula, you can either create "helper" properties that hold variables, or you can create monster formulas that perform the same functions multiple times.