F
Firoz Khan
how do I calculate days of every month from a given period (start date and
end date)
end date)
Hi Jacob,
thanks for your reply
it seems my qstn was not clear enough
is it possible to get the result as below ?
Date In Date Out Jan Feb Mar
9-Jan-09 16-Mar-09 22 29 15
where Date In and Date Out is input data and Jan, Feb and Mar are results
is there any formula to get the days of every month for a given period of
time ?
regards
Firoz
Let's say you have dates in C1 to N1, formatted as mmm so it displays Jan
through Dec.
In C2, enter:
=IF(MONTH(C$1)<MONTH($A2),0,IF(MONTH(C$1)=MONTH($A2),EOMONTH($A2,0)-$A2,IF(MONTH(C$1)<MONTH($B2),DAY(DATE(YEAR($A2),MONTH(C$1)+1,0)),IF(MONTH(C$1)=MONTH($B2),DAY($B2),0))))
Copy across to N2, and down if appropriate.
By the way the correct answers for your example are 28 days for February and
16 days for March.
Regards,
Fred
Hi Jacob,
thanks for your reply
it seems my qstn was not clear enough
is it possible to get the result as below ?
Date In Date Out Jan Feb Mar
9-Jan-09 16-Mar-09 22 29 15
where Date In and Date Out is input data and Jan, Feb and Mar are results
is there any formula to get the days of every month for a given period of
time ?
regards
Firoz
Some minor changes should be made in my formula depending on how you want to
count.
For example, in your example, you are apparently not counting either the first
or the last day of the interval.
Is that what you want?
The formula I first proposed doesn't count the first day (day_in) but does
count the last day.
If you want to include BOTH the first and last day of the interval in your
count, then, with the same setup as before, try:
C2:
=IF($B2>$A2,SUMPRODUCT(--(MONTH(ROW(INDIRECT($A2&":"&$B2)))=MONTH(C$1))),"")
Fill right to N2 and down as far as required.
If you don't want to count either the Date_In or Date_Out (or both), merely add
1 to Date_In, or subtract 1 from Date_out, as appropriate.
e.g. -- to not count first but count last (similar to what you posted):
=IF($B2>$A2,SUMPRODUCT(--(MONTH(ROW(INDIRECT($A2+1&":"&$B2)))=MONTH(C$1))),"")
--ron