# Formula to check if Year & Month are the same.

#### howardJennings

##### New Member
I have a complicated spread sheet which calculated insurance premiums. part of the sheet calculated the 'billing period'
it's pretty simple
IF the 'Effective Date" is this before the invoice date billing period = number of days in the month
ELSE Billing period is Number of days in the month LESS the 'Effective Date".

I have to check whether the 'Effective Date" YEAR & MONTH are the same as the 'Billing Date' YEAR & MONTH (i'm ignoring the day). The formula I'm using to do this is

=IF(AND(YEAR(H10)=YEAR(\$E\$3),MONTH(H10=MONTH(\$E\$3))),"TRUE","FALSE")

Cell H10 & E3 contain the date that i need to check.

The formula works once or twice and then stops, what have i done wrong?

### Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

#### NeonRedSharpie

##### Well-known Member
What do you mean "stops"?

#### howardJennings

##### New Member
CELL E3 is the fixed date to reference

CELL H10 is the cell you'd enter the "effective Date' in

the first time i enter a date in H10 the formula calculates correctly and displys either 'TRUE" or "FALSE"

however it's hit or miss whether it will calculate correctly again if i change the date in H10

#### howardJennings

##### New Member
DOH! I've just noticed a missed ')'

Bugger!

#### MarcelBeug

##### Well-known Member
If you want real TRUEs and FALSEs instead of strings "TRUE" and "FALSE", you can shorten your fomula to
Code:
``=AND(YEAR(H10)=YEAR(\$E\$3),MONTH(H10)=MONTH(\$E\$3))``

Last edited:

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,164,669
Messages
5,838,687
Members
430,563
Latest member
Raeyven

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back