+ Reply to Thread
Results 1 to 6 of 6

Count number of times a specific date happens between two dates

  1. #1
    Registered User
    Join Date
    11-06-2014
    Location
    US
    MS-Off Ver
    2013
    Posts
    5

    Count number of times a specific date happens between two dates

    Hello everyone

    I'm trying to figure out how to count the number of times a specific date happens between two dates. I use a lot of countif functions for other things, but I can't seem to get it to work for this particular problem. Here's an example of what I'm trying to do:

    Start Date: 5/15/13
    End Date: 12/10/13
    Date: 15th
    Number of times the 15th happens between those dates: 7

    How can I get to the answer with an excel formula? Is it possible?

    Thanks in advance for your help!

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Count number of times a specific date happens between two dates

    e3 Start
    e4 end
    d6: date

    =IF(DAY(E3)>=D6,IF(DAY(E4)>=D6,DATEDIF(E3,E4,"m")+2,DATEDIF(E3,E4,"m")+1),DATEDIF(E3,E4,"m")
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Count number of times a specific date happens between two dates

    Hi, and welcome to the forum.

    =DATEDIF(start_date,end_date,"m")+1
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Count number of times a specific date happens between two dates

    I did this with a helper column (B)...
    A
    B
    C
    1
    5/15/2013
    12/10/2013
    2
    4/15/2013
    15
    7
    3
    4/16/2013
    16
    4
    5/15/2013
    15
    5
    5/16/2013
    16
    6
    6/15/2013
    15
    7
    6/16/2013
    16
    8
    7/15/2013
    15
    9
    7/16/2013
    16
    10
    8/15/2013
    15
    11
    8/16/2013
    16
    12
    9/15/2013
    15
    13
    9/16/2013
    16
    14
    10/15/2013
    15
    15
    10/16/2013
    16
    16
    11/15/2013
    15
    17
    11/16/2013
    16
    18
    12/15/2013
    15
    19
    12/16/2013
    16

    B2=DAY(A2)
    C2=COUNTIFS($A$2:$A$19,">="&$A$1,$A$2:$A$19,"<="&$B$1,$B$2:$B$19,15)
    both copied down
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

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

    Re: Count number of times a specific date happens between two dates

    Quote Originally Posted by daffodil11 View Post
    =IF(DAY(E3)>=D6,IF(DAY(E4)>=D6,DATEDIF(E3,E4,"m")+2,DATEDIF(E3,E4,"m")+1),DATEDIF(E3,E4,"m")
    I see the logic that you're aiming for but I don't think this works in all cases, e.g. 10th July to 25th September in the same year includes 3 "15ths" but your formula returns 2

    Using a similar logic and with start date in A2, end date in B2 and day to count in C2 (15 in the example) you can use this formula which should work in all cases assuming the day to count is one that occurs every month (i.e. <= 28)

    =DATEDIF(A2-DAY(A2)+1,B2,"m")+1-(DAY(A2)>C2)-(DAY(B2)<C2)

    ....or for a completely different approach but same result

    =SUMPRODUCT(--(DAY(ROW(INDIRECT(A2&":"&B2)))=C2))

    That latter formula can also be used to give an accurate count of days that don't occur every month, e.g. 29, 30 or 31
    Audere est facere

  6. #6
    Registered User
    Join Date
    11-06-2014
    Location
    US
    MS-Off Ver
    2013
    Posts
    5

    Re: Count number of times a specific date happens between two dates

    Quote Originally Posted by daddylonglegs View Post

    ....or for a completely different approach but same result

    =SUMPRODUCT(--(DAY(ROW(INDIRECT(A2&":"&B2)))=C2))

    That latter formula can also be used to give an accurate count of days that don't occur every month, e.g. 29, 30 or 31
    Thank you for your help everyone! I don't use excel coercion or indirect functions that often, so I wouldn't have come up with this one on my own.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 05-28-2010, 04:57 PM
  2. [SOLVED] Count number of times a specific number is displayed in a cell ran
    By subs in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  3. [SOLVED] Count number of times a specific number is displayed in a cell ran
    By N Harkawat in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 04:05 AM
  4. [SOLVED] Count number of times a specific number is displayed in a cell ran
    By subs in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  5. Count number of times a specific number is displayed in cells
    By subs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2005, 11:05 AM

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