How do I get the number of months that overlap between two sets of dates?

If one has Office 365 Excel we can use FILTER to return the months that coincide. And Unique to return the unique list. Then count to count the number of months:

=COUNT(UNIQUE(FILTER(MONTH(SEQUENCE(B1-A1,,A1)),ISNUMBER(MATCH(SEQUENCE(B1-A1,,A1),SEQUENCE(B2-A2,,A2),0)),"")))

enter image description here

The SEQUENCE returns arrays that start at the first day and end at the day before the end date. Then we use MATCH to see if that date is in the second list of dates. If so we return the month of the first date.

The the UNIQUE will only return the month numbers which are in both lists and COUNT will count them.