Solved

Check if date is between 2 dates

Posted on 2011-03-16
6
307 Views
Last Modified: 2012-05-11
I see a solution for this question using visual basic, however I am looking to use it in an Excel function. In the example attached I want to sum a range of values if the date is between two other dates.

I know I can sum if the date is greater or less than a specified date:

 =SUMIF($A2:$A4,"<39814",C$2:C$4) where the criteria is the Excel date as a serial number (in this case, before 1/1/09).

How can I do this if I want to sumif the date is between two dates? I tried this:

=SUMIF($A2:$A4,AND("<398149",">=39448"),B$2:B$4) where the criteria is supposed to be any date in 2008.

I get a result of 0.

Also, I want to reference cells containing the date, not the Excel date serial value. See the attached example.

 Sumif-example.xls
0
Comment
Question by:orerockon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 50

Expert Comment

by:barry houdini
ID: 35149031
You can use SUMPRODUCT like this

=SUMPRODUCT((A3:A6>=A4)*(A3:A6<=A5),B3:B6)

regards, barry
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
ID: 35149079
...obviously you wouldn't normally have the criteria dates as part of the criteria range, that was just by way of example....criteria dates, A4 and A5 should ideally be in different cells. Note that for a whole year only you could use YEAR function like this:

=SUMPRODUCT((YEAR(A3:A6)=2008)+0,B3:B6)

regards, barry
0
 
LVL 19

Expert Comment

by:Arno Koster
ID: 35149144
or from excel version 2003 you could also use

=SUMIFS(B2:B6;A2:A6;"<40179";A2:A6;">39813")

to get the total for 2009
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:akajohn
ID: 35149164
Or if you really like sumif

=SUMIF(A2:A6,"<="&$A$5,B2:B6)-SUMIF(A2:A6,"<"&$A$4,B2:B6)
0
 
LVL 1

Expert Comment

by:anonxxxx2011
ID: 35149782
Plug this formula into your cell
=SUM(IF(AND(A2>=A15,A2<A16),B2,0),IF(AND(A3>=A15,A3<A16),B3,0),IF(AND(A4>=A15,A4<A16),B4,0),IF(AND(A5>=A15,A5<A16),B5,0),IF(AND(A6>=A15,A6<A16),B6,0))

The long-winded way.
0
 

Author Closing Comment

by:orerockon
ID: 35151728
Exactly what I was looking for thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question