The equality (`==`

) operator returns true if its operands are equal. It accepts operands of all data types – strings, numbers, Booleans, and dates.

```
string == string
number == number
Boolean == Boolean
date == date
equal(string, string)
equal(number, number)
equal(Boolean, Boolean)
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 // Output: True
equal(1,1) // Output: True
1 == 2 // Output: False
"1" == 1 // Type mismatch error
+"1" == 1 // Output: True (uses the unaryPlus operator to convert "1" to a number
2^2 == 4 // Output: True
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:

- First, obtain the last day of the month:
- Add 1 month to the current date in the Date property, using dateAdd().
- 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`

) - 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`

).

- 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.
- 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.
- 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

```
// Compressed
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")))
// Expanded and Commented
if(
// Check if the day of the week index for Last Day
// is 0 (Sunday).
day(
prop("Last Day")
) == 0,
// If it is 0, subtract 2 days from Last Day to arrive at the
// nearest weekday (Friday).
dateSubtract(
prop("Last Day"), 2, "days"
),
// If it isn't 0, next check if the day of the week index
// for Last Day is 6 (Saturday).
if(
day(
prop("Last Day")
) == 6,
// If it is 6, subtract 1 day from Last Day to arrive at
// the nearest weekday (Friday).
dateSubtract(
prop("Last Day"), 1, "days"
),
// If the day of the week index isn't 0 or 6, output the
// Last Day property as-is.
prop("Last Day")
)
)
```

### “Last Day” Property Formula

```
// Compressed
dateSubtract(dateAdd(prop("Date"), 1, "months"), date(dateAdd(prop("Date"), 1, "months")), "days")
// Expanded and Commented
// Get the last day of the current month by adding 1 month to the current Date,
// then subtracting the number of days in that date's date() index.
dateSubtract(
// Add 1 month to the current date.
// E.g. - May 11 + 1 month == June 11
dateAdd(
prop("Date"), 1, "months"
),
// Get the number of days to be subtracted using the date()
// function. E.g. - June 11 == 11
date(
dateAdd(
prop("Date"), 1, "months"
)
),
// Specify the date unit to be subtracted; in this case, "days"
"days"
)
```

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
if(day(dateSubtract(dateAdd(prop("Date"), 1, "months"), date(dateAdd(prop("Date"), 1, "months")), "days")) == 0, dateSubtract(dateSubtract(dateAdd(prop("Date"), 1, "months"), date(dateAdd(prop("Date"), 1, "months")), "days"),2,"days"), if(day(dateSubtract(dateAdd(prop("Date"), 1, "months"), date(dateAdd(prop("Date"), 1, "months")), "days")) == 6, dateSubtract(dateSubtract(dateAdd(prop("Date"), 1, "months"), date(dateAdd(prop("Date"), 1, "months")), "days"),1,"days"), dateSubtract(dateAdd(prop("Date"), 1, "months"), date(dateAdd(prop("Date"), 1, "months")), "days")))
// 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(
dateAdd(
prop("Date"), 1, "months"
),
date(
dateAdd(
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(
dateAdd(
prop("Date"), 1, "months"
),
date(
dateAdd(
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(
dateAdd(
prop("Date"), 1, "months"
),
date(
dateAdd(
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(
dateAdd(
prop("Date"), 1, "months"
),
date(
dateAdd(
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(
dateAdd(
prop("Date"), 1, "months"
),
date(
dateAdd(
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, everywhere 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.