# Calculating precise number of months between two specific dates

##### New Member
Hello. I'd really like some help with this. I really appreciate any replies.

I need to do forecasting on salary costs for staff members. They are paid a salary which is divided equally between the months. So if their salary is £36,000, then they get paid £3,000 in February, and £3,000 in March, and £3,000 in every month of the year.

I have been trying to tweak the below formulae which I've found in a thread from 2012. Both formula does the same thing. However, currently those formulae assume that the start date is to be discounted from the answer, but I need it to be inclusive.

=(DAY(EOMONTH(A1,0))-DAY(A1))/DAY(EOMONTH(A1,0))+DATEDIF(A1,B1,"m")-1+DAY(B1)/DAY(EOMONTH(B1,0))

=DATEDIF(A2,B2,"m")+DAY(B2)/DAY(EOMONTH(B2,0))-DAY(A2)/DAY(EOMONTH(A2,0))

Thus, someone will work for us as follows:
Start date: 01/07/2021 (or 07/01/2021 in US terminology)
End date: 31/12/2021
This is exactly 6.0 months. But using the above formulae I get 5.96774 months, because it's subtracting 1st July.

What I need is the precise formula which would also include 1st July in the months counted.

But it also needs to work if someone is commencing or departing at any point in a month, not necessarily just the start/end of a month

Many thanks in advance
Paul

### Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

#### Candyman8019

##### Active Member
You could try something along this line substituting the dates for your specific cell:
=MONTH(DATE(2021,7,1)-DATE(2021,1,7))

#### mart37

##### Well-known Member
=DATEDIF(DATE(YEAR(A1),MONTH(A1),1),DATE(YEAR(B1),MONTH(B1),DAY(EOMONTH(B1,0)))+1,"m")

#### Fluff

##### MrExcel MVP, Moderator
Hi & welcome to MrExcel.
Maybe
Excel Formula:
``=DATEDIF(A2,B2,"m")+DAY(B2)/DAY(EOMONTH(B2,0))-(DAY(A2)-1)/DAY(EOMONTH(A2,0))``

##### New Member

=DATEDIF(DATE(YEAR(A1),MONTH(A1),1),DATE(YEAR(B1),MONTH(B1),DAY(EOMONTH(B1,0)))+1,"m")
Thank you for your reply. Unfortunately this only gives a whole number of months. If the start date is, say, 11th June, and the end date is the end of a month, then I'll want the answer to show .667

##### New Member
=DATEDIF(A2,B2,"m")+DAY(B2)/DAY(EOMONTH(B2,0))-(DAY(A2)-1)/DAY(EOMONTH(A2,0))

Unfortunately, if I enter a start date of 09/12/2020, and an end date of 05/01/2021, the formula gives an answer of -0.0968.

#### Fluff

##### MrExcel MVP, Moderator

In that case can you please post some sample data showing expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

#### Fluff

##### MrExcel MVP, Moderator
Maybe
Excel Formula:
``=YEARFRAC(A2,B2)*12``
Failing that I will need examples

##### New Member
In that case can you please post some sample data showing expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
Thanks, Fluff, for getting back so swiftly.

Essentially, every whole month between the two dates should count as 1.0, and the two months which are included in the specified dates should be >0.0-1.0, depending how much of the month is covered. I give some examples of this below.

 01/01/2021​ 31/12/2021​ 12​ 18/02/2021​ 25/07/2021​ 5.1993088​ 19/02/2021​ 15/09/2021​ 5.8571429​ 20/02/2021​ 15/09/2021​ 5.8214286​ 21/02/2021​ 27/11/2021​ 9.1857143​ 22/02/2021​ 28/11/2021​ 9.1833333​ 23/02/2021​ 29/11/2021​ 9.1809524​ 24/02/2021​ 03/09/2025​ 53.278571​ 25/02/2021​ 03/09/2025​ 53.242857​ 26/02/2021​ 04/09/2025​ 53.240476​ 27/02/2021​ 25/02/2025​ 46.964286​ 28/02/2021​ 17/01/2022​ 9.5841014​

Essentially, what I have done here is use the formula I posted in my OP, but included a second column (hidden above) which simply subtracts one day from the first column. This means that the forumla now works, but I would really like this to work without having to add an additional column.

Sorry, I'll have to see if I can upload this as a spreadsheet! Many thanks again!

##### New Member
Maybe
Excel Formula:
``=YEARFRAC(A2,B2)*12``
Failing that I will need examples
This is getting very close.

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,282
Messages
5,836,401
Members
430,425
Latest member
xlsee

### 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?

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