# Date functions in IF Statement

Options
✭✭✭✭

Hi, I'm trying to get the previous month and previous year via a formula. Here is the formula I am  trying to use:

=IF(MONTH(TODAY()) = "2", MONTH(TODAY()) - 1 + "/" + YEAR(TODAY()) - 1, "false")

It works when I remove the -1 from the YEAR(TODAY()) - 1 part, but when I add the -1 back in I get #INVALID OPERATION. Any ideas? Thanks!

Tags:

• ✭✭✭✭
Options

Same thing happens if I try it outside of an IF Statement:

=MONTH(TODAY()) - 1 + "/" + YEAR(TODAY()) -1

• ✭✭✭✭✭✭
Options

Can you add some parentheses around the year part?

=MONTH(TODAY()) - 1 + "/" + (YEAR(TODAY()) - 1)

I think the formula might be getting confused after the + to concatenate text and then going back to doing number math (that's my totally non-technical explanation).

• ✭✭✭✭
Options

HI, Thanks! That works outside of the IF statement, but when I put it back in the IF statement I get the #INVALID OPERATION error again with or without the parentheses.

=IF(MONTH(TODAY()) = "2", MONTH(TODAY()) - 1 + "/" + YEAR(TODAY()) - 1), "false")

=IF(MONTH(TODAY()) = "2", MONTH(TODAY()) - 1 + "/" + YEAR(TODAY()) - 1, "false")

• ✭✭✭✭✭✭
Options

Did you try:

=IF(MONTH(TODAY()) = "2", MONTH(TODAY()) - 1 + "/" + (YEAR(TODAY()) - 1), "false")

😉

• ✭✭✭✭
Options

Boom! That did it. Missing parentheses... Thanks much!

• ✭✭✭✭✭✭
Options

No problem!

Keep an eye on those parentheses - small but mighty (and best kept in pairs).

## Help Article Resources

Want to practice working with formulas directly in Smartsheet?

Check out the Formula Handbook template!