ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   CALCULATE DAYS PER MONTH BETWEEN 2 DATES (https://www.excelbanter.com/excel-worksheet-functions/238542-calculate-days-per-month-between-2-dates.html)

wildliferehabber

CALCULATE DAYS PER MONTH BETWEEN 2 DATES
 
I am trying to calculate days between a start date and end date for each
month. If start date and end date are same day, formula should return 1.
Columns A-AD are in use for other data. Below is an example of what I want to
see. Help, please?

Example:
A B ... N €¦ R S T €¦ AB AC
1 Start End JAN FEB MAR NOV DEC
2 1/2/09 1/2/09 1
3 1/16/09 3/27/09 16 28 27
4 2/3/09 3/11/09 26 11
5 11/13/09 12/13/09 18 13
6 1/12/09 12/1/09 20 28 31 30 1



Lars-Åke Aspelin[_2_]

CALCULATE DAYS PER MONTH BETWEEN 2 DATES
 
On Thu, 30 Jul 2009 12:16:01 -0700, wildliferehabber
wrote:

I am trying to calculate days between a start date and end date for each
month. If start date and end date are same day, formula should return 1.
Columns A-AD are in use for other data. Below is an example of what I want to
see. Help, please?

Example:
A B ... N … R S T … AB AC
1 Start End JAN FEB MAR NOV DEC
2 1/2/09 1/2/09 1
3 1/16/09 3/27/09 16 28 27
4 2/3/09 3/11/09 26 11
5 11/13/09 12/13/09 18 13
6 1/12/09 12/1/09 20 28 31 30 1



With the start date in cell A2 and the end date in cell B2, try the
following in cell C2:

=SUMPRODUCT(--(DATE(YEAR($A2),COLUMN(A1),
ROW(OFFSET($A1,,,DAY(DATE(YEAR($A2),COLUMN(B1),0)) ,)))=$A2))
-SUMPRODUCT(--(DATE(YEAR($A2),COLUMN(A1),
ROW(OFFSET($A1,,,DAY(DATE(YEAR($A2),COLUMN(B1),0)) ,)))$B2))

Copy this formula to the right thru cell N2.
Then copy cells C2:N2 down as far as you have data in columns A and B.

Note: This formula will only work if there is only one calendar year
involved, i.e. the start date and end date within the same year.

Hope this helps / Lars-Åke



barry houdini[_17_]

CALCULATE DAYS PER MONTH BETWEEN 2 DATES
 

If your header row contains dates, i.e. the 1st of each month (you can
custom format these as mmm if you just want to display "Jan","Feb" etc.)
then you can use this formula in C2 copied across and down

=MAX(0,MIN($B2,C$1+31-DAY(C$1+31))-MAX($A2,C$1)+1)


--
barry houdini
------------------------------------------------------------------------
barry houdini's Profile: http://www.thecodecage.com/forumz/member.php?userid=72
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=121159


Lars-Åke Aspelin[_2_]

CALCULATE DAYS PER MONTH BETWEEN 2 DATES
 
On Thu, 30 Jul 2009 23:14:06 +0100, barry houdini
wrote:


If your header row contains dates, i.e. the 1st of each month (you can
custom format these as mmm if you just want to display "Jan","Feb" etc.)
then you can use this formula in C2 copied across and down

=MAX(0,MIN($B2,C$1+31-DAY(C$1+31))-MAX($A2,C$1)+1)


This is nice. However, be aware the limitation that the start and end
dates must be within the calendar year that you have used for the
header row dates.
When you have a new year you will need a new header row.

Lars-Åke


All times are GMT +1. The time now is 09:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com