Solved

Check if date is between 2 dates

Posted on 2011-03-16
6
301 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:akoster
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
Technology Partners: 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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