+ Reply to Thread
Results 1 to 9 of 9

How do i write a formula to count the number of days in a date range, split per month

  1. #1
    Registered User
    Join Date
    01-23-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2003
    Posts
    4

    How do i write a formula to count the number of days in a date range, split per month

    Hi, sorry if this has previously been posted and solved but the search funtion doesnt work on my browser at work.

    I have a large spreadsheet which holds lots of data with date ranges that i need to performs different actions to. im currently trying to figure out a way to identify the number of days, per calender month, that falls in a date range.

    sample data...

    Start Date End Date Old Value New Value
    08/03/2010 18/06/2010 16758.2 16758.1
    19/06/2010 04/08/2010 16758.2 -224147.3
    05/08/2010 17/01/2011 16758.2 2923.1




    i need to break down the total number of days per month

    Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
    24 30 31 18
    12 31 4
    27 30 31 30 31


    As you can see this also laps into a new year, which poses my next problem, ill probably just add more columns on to the end of the table for that though...

    I will later apply different calculations to these cells but in short need to get a calculation for the number of days per month first.

    (in short spreading the new value out accross the year then multiplying it by the days... i also need to apply a further daily volume cal to it)
    can any one help at all please?

    Ta
    Ben
    Last edited by benwwatson; 01-23-2012 at 09:25 AM.

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: How do i write a formula to count the number of days in a date range, split per m

    Hi Ben and welcome to the forum

    You can use SUMPRODUCT for this. =SUMPRODUCT(MONTH(A1:A500))=......

    sOMETING LIKE THIS.

    wOULD YOU LIKE TO UPLOAD A SAMPLE WORKBOOK??
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Registered User Chappo's Avatar
    Join Date
    09-04-2006
    Posts
    33

    Re: How do i write a formula to count the number of days in a date range, split per m

    This formula should help you.

    =IF(ISERROR(DATEDIF(MAX([Start Date],[Current Month]),MIN([End Date],[Next Month]),"d"))=TRUE,"",DATEDIF(MAX([Start Date],[Current Month]),MIN([End Date],[Next Month]),"d"))
    "There has never been reported stomach aches or related medical trauma that takes place after swallowing your pride.
    "
    - Daisuke Aramaki

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: How do i write a formula to count the number of days in a date range, split per m

    Hello Ben,

    Assuming you have start date in A2 and end date in B2 try putting the 1st of each month in F1 across and then you can use this formula in F2 copied across and down

    =MAX(0,MIN($B2,G$1-1)-MAX($A2,F$1)+1)

    See attached. Note that I formatted row 1 to show just mmm-yy and I formatted the result cells so that zero displays as blank. With that formula you need the date headers to go one month further than the data.....[so if you put Feb-11 in S1 you'll get 17 in R4]
    Attached Files Attached Files
    Last edited by daddylonglegs; 01-23-2012 at 09:14 AM.
    Audere est facere

  5. #5
    Registered User
    Join Date
    01-23-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: How do i write a formula to count the number of days in a date range, split per m

    Hi Guys thanks for this, sadly i cant upload a spreadsheet as i am working with sensetive information... i will try and create a dummy in in a bit.

    Chappo, this gives me the total days over the period, i need to split it by month. march as a single figure needs to say "24" inclusive of the 8th if possible.

  6. #6
    Registered User
    Join Date
    01-23-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: How do i write a formula to count the number of days in a date range, split per m

    Quote Originally Posted by daddylonglegs View Post
    Hello Ben,

    Assuming you have start date in A2 and end date in B2 try putting the 1st of each month in F1 across and then you can use this formula in F2 copied across and down

    =MAX(0,MIN($B2,G$1-1)-MAX($A2,F$1)+1)

    See attached. Note that I formatted row 1 to show just mmm-yy and I formatted the result cells so that zero displays as blank. With that formula you need the date headers to go one month further than the data.....[so if you put Feb-11 in S1 you'll get 17 in R4]

    now this has got realy potential... thank you for this one!!

  7. #7
    Registered User Chappo's Avatar
    Join Date
    09-04-2006
    Posts
    33

    Re: How do i write a formula to count the number of days in a date range, split per m

    Quote Originally Posted by benwwatson View Post
    Hi Guys thanks for this, sadly i cant upload a spreadsheet as i am working with sensetive information... i will try and create a dummy in in a bit.

    Chappo, this gives me the total days over the period, i need to split it by month. march as a single figure needs to say "24" inclusive of the 8th if possible.
    Just FYI, the formula I provided did split by month.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-23-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: How do i write a formula to count the number of days in a date range, split per m

    Ah then it was my dodgy cell references that gave me the incorrect answers!! thank you all the same though!!

  9. #9
    Registered User
    Join Date
    12-03-2013
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: How do i write a formula to count the number of days in a date range, split per m

    Quote Originally Posted by chappo View Post
    just fyi, the formula i provided did split by month.
    it was very helpful to me. Thanks alot

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1