How do I calculate the difference between dates? [duplicate]


0

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?


I have no idea how to form a formula
Jadran


I need only number of days from month who have 31 days (7, 8, 10, and 12 month) from two dates 1.7.2016 to 5.12.2016
Jadran

Where does the +4 come in?
Scott Craner

+4 come from 12 month
Jadran

Відповіді:


4

How do I calculate the difference between 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.

enter image description here

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.

Source Calculate the difference between two dates - Excel


0

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.

enter image description here


Thanks Scott. This formula je ok but can you tel me what is (A:A in formula?
Jadran

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.
Scott Craner

Remember that if this worked for you to mark as correct by clicking the check mark by the answer.
Scott Craner
Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.