SOLVED

calculating months between two dates with rounding

Copper Contributor

qdanazumi_2-1660206650006.png

I have been trying to look for the number between these two months while rounding to the next month if the day passes the 15th

11 Replies

@qdanazumi 

Calculate the difference between two dates

Use the DATEDIF function when you want to calculate the difference between two dates. First put a start date in a cell, and an end date in another. Then type a formula like one of the following.

 

You can download an example workbook with all of the examples in this article.

You can follow along, or create your own formulas.

 

@NikolinoDE what if I wanted after the 15 of each the month to round it to the next month

@NikolinoDE The formula didn't end up working, unfortunately. 

 07/01/22 08/20/23

I know that because 8/31/23 is past the 15th of the month I would round it to the next month so I'm pretty much looking for the total number of months between 7/1/22 and 9/1/23. I know the total number of months is 14. What formula should I use to figure that out?

 

best response confirmed by NikolinoDE (Gold Contributor)
Solution

@qdanazumi 

With dates in A3 and B3:

 

=(12*YEAR(B3)+MONTH(B3)+(DAY(B3)>15))-(12*YEAR(A3)+MONTH(A3)+(DAY(A3)>15))

I tried this formula and unfortunately, it didn't work. The formula @hans gave seems to work
how would I change the format of the cell
Select cell or range of cells
right mousekey
Select "Format Cells...".
Numbers -> Set to "Default".

@NikolinoDE 

Hi Niko,

 

Your formula doesn't work correctly if the dates are more than a year apart, nor if the month number of the first date is larger than the month number of the second date:

S1653.png

That's right, you're absolutely right...strange...I have to find out why this is happening.

Qdanazumi: Please use Mr. Hans Vogelaar's formula and ignore mine.
sry for the circumstances.

@NikolinoDE 

It's because you subtract two month numbers without taking the year into account, so the result will vary from 1-12 = -11 to 12-1 = 11.

1 best response

Accepted Solutions
best response confirmed by NikolinoDE (Gold Contributor)
Solution

@qdanazumi 

With dates in A3 and B3:

 

=(12*YEAR(B3)+MONTH(B3)+(DAY(B3)>15))-(12*YEAR(A3)+MONTH(A3)+(DAY(A3)>15))

View solution in original post