This question already has an answer here:
I have 2 dates 1.7.2016 and 5.12.2016, and I need to calculate number of days from month with 31 day (31+31+31+4=98).
How can I get the number of days?
+4
come in?
This question already has an answer here:
I have 2 dates 1.7.2016 and 5.12.2016, and I need to calculate number of days from month with 31 day (31+31+31+4=98).
How can I get the number of days?
+4
come in?
Відповіді:
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.
In this example, the start date is in cell D9, and the end date is in E9. The formula is in F9. The “d” returns the number of full days between the two dates.
Use SUMPRODUCT to iterate through the dates and sum up the ones that fall in the months with 31 days:
=SUMPRODUCT(--(DAY(EOMONTH(ROW(INDEX(A:A,A1):INDEX(A:A,B1)),0))=31))
ROW(INDEX(A:A,A1):INDEX(A:A,B1))
creates an array of the dates from the start to the finish.
EOMONTH(...,0)
finds the last date of that month.
DAY(...)
returns the numerical day.
(...=31)
tests if that day is 31. If so it resolves to TRUE otherwise FALSE.
--
turns the TRUE/FALSE into 1/0 respectively.
SUMPRODUCT(...)
Cause the formula to iterate through the array above testing each date in turn and adding the 1s and 0s together.
A:A
is just a place holder, it can be any column. It does not mater as long as it is a full column. We are returning a row number and not a physical value. So it does not mater which column is used. It could be XAA:XAA
and still work.