Counting months

robertdseals

Active Member
Joined
May 14, 2008
Messages
334
Office Version
  1. 2010
Platform
  1. Windows
Hello,
I'm trying to count the number of complete months between two dates. 1/15/23 - 5/21/23 would equal 3. The problem occurs that they also want to include months that start on a weekend. So, if someone starts on monday the 2nd, they would get credit for that entire month. Lastly, you would need to take into account holidays (US). So, if someone was hired on September 4th because the 1st was on Saturday and memorial day was on Monday they would still get credit for the entire month. But, if they were hired on the 4th of another month without a holiday, they wouldn't get credit for that month.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
can you give a broad range of examples and expected results in a table or even a XL2BB add in (link below) mini worksheet? You're asking the forum to manually recreate your scenario and they can take time, and/or have error of assumptions or typos (which also causes more time).

Thanks in advance.
 
Upvote 0
See if the following formula works for you:
Excel Formula:
=ROUND((TEXT(B2,"yyyy mm\/\1\2")-TEXT(A2,"yyyy mm\/\1\2"))*12,0)+(WORKDAY(A2-1,1,Holidays)=WORKDAY(EOMONTH(A2,-1),1,Holidays))+(WORKDAY(B2,1,Holidays)-1=EOMONTH(B2,0))-1
where cell A2 contains the start date, cell B2 contains the end date, and a range named Holidays contains holiday dates.
 
Upvote 0
MrExcelPlayground17.xlsx
BCDE
2StartEndWhole MonthsHolidays
3Tuesday, September 4, 2029Friday, September 28, 20291Monday, January 1, 2029
4Wednesday, September 5, 2029Wednesday, October 31, 20291Monday, September 3, 2029
5Tuesday, September 4, 2029Wednesday, October 31, 20292Wednesday, July 4, 2029
6Wednesday, September 5, 2029Wednesday, October 31, 20291
7Wednesday, September 5, 2029Tuesday, December 25, 20292
8Wednesday, September 5, 2029Monday, December 31, 20293
9Wednesday, September 5, 2029Friday, February 15, 20304
Sheet23
Cell Formulas
RangeFormula
D3:D9D3=MAX(0,IF(NETWORKDAYS(C3,EOMONTH(C3,0),$E$3:$E$8)=1,(YEAR(C3)*12+MONTH(C3)),(YEAR(C3)*12+MONTH(C3))-1)-IF(NETWORKDAYS(EOMONTH(B3,-1)+1,B3,$E$3:$E$8)=1,(YEAR(B3)*12+MONTH(B3)),(YEAR(B3)*12+MONTH(B3))+1)+1)
 
Upvote 0
Solution

Forum statistics

Threads
1,215,201
Messages
6,123,617
Members
449,109
Latest member
Sebas8956

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top