How to compare 2 dates by MONTH+YEAR

Why I cant to write so to compare 2 values? Expression result here is YES/NO I think:

MONTH(orders[order_date]) & YEAR(orders[order_date]) = MONTH(TODAY()) & YEAR(TODAY())

but it is right:  MONTH(TODAY())&YEAR(TODAY()) = 32022

Solved Solved
0 4 1,746
1 ACCEPTED SOLUTION

For matching:

AND( 
  MONTH([order_date]) = MONTH(TODAY),
  YEAR([order_date]) = YEAR(TODAY)
)

For calculating the number of months between two dates:

MONTH([date2]) - MONTH([date1]) +
IF( YEAR([date2]) = YEAR([date1]), 
  0, 
  12 * (YEAR([date2]) - YEAR([date1])
)

View solution in original post

4 REPLIES 4

Your expression is all wrong. 

  • "&" is not a logical operator.
  • You have to use AND() which is a command not an operator.
  • orders[order_date] is a list of values, not a single value, while [order_date] is a single value of the column that can be of any column type.

Please read the following guides:

Expressions: The Essentials | AppSheet Help Center

Yes/No Expressions | AppSheet Help Center

AND() | AppSheet Help Center 

It can be good compared as text, and it works:

IF( IN("*", SELECT(orders[price],
AND([hUID] = [_THISROW].[hUID],
text([order_date])&year([order_date])) = text(MONTH(TODAY())&YEAR(TODAY()))
))), "1", "")

---- But I looking for any formula to compare month quantity between 2 dates, like DATEDIF (what works in GoogleSheets. Is here any same? Or what is better way to calculate how many months between 12.10.2021 and 05.03.2022 ?

For matching:

AND( 
  MONTH([order_date]) = MONTH(TODAY),
  YEAR([order_date]) = YEAR(TODAY)
)

For calculating the number of months between two dates:

MONTH([date2]) - MONTH([date1]) +
IF( YEAR([date2]) = YEAR([date1]), 
  0, 
  12 * (YEAR([date2]) - YEAR([date1])
)

Thanks, I understood concept 🙂

Top Labels in this Space