Formula IF function with time range condition

Copperlinks

New Member
Joined
Jul 22, 2010
Messages
5
Hello all,
I am attempting to create an If function with time and having difficulty with it.

What I am trying to accomplish is to create a condition between two cells in which a particular range of time is met.

For example:
If time between A1 and B1 fall within the range between 5:15 PM and 5:45 PM, then C1 = 1. So if it's 5:05 PM in A1 and 6:01 PM in B1, value is true. If it's 5:25 in A1 and 5:26 PM in B1, value is still true. If it's 5:46 PM in A1 and 6:01 PM in B1, value is false.

Can this be done?
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

ChrisM

Well-known Member
Joined
Jun 11, 2002
Messages
2,129
Sure, you just end up testing both of your input times against the lower bound, then both of them against the upper bound.

assume 5:15 in D1 and 5:45 in E1:

=If(AND(A1>=D1,B1>=D1,A1<=E1,B1<=E1),1,0)
 

Copperlinks

New Member
Joined
Jul 22, 2010
Messages
5
Thank you so much for your assistance, Chris. Unfortunately, the formula is still equaling zero on every test. I'll brainstorm a bit more to see if I can identify the problem, but I suspect it has something to do with the unique format that times and dates present.
 

Copperlinks

New Member
Joined
Jul 22, 2010
Messages
5
Ah, no, I see what the issue is. The value is only true when the time encompasses the entirety of 5:15 and 5:45. I need it to be true even if it's 1 minute within the range between 5:15 and 5:45.
 

ChrisM

Well-known Member
Joined
Jun 11, 2002
Messages
2,129

ADVERTISEMENT

Whoops, you're right, I goofed. Let's try this logic:

Your start time must always be less than 5:45
AND
Your end time must always be greater than 5:00

I think that will work right?

Code:
=If(AND(A1 < E1,B1 > D1),1,0)
 

Copperlinks

New Member
Joined
Jul 22, 2010
Messages
5
I have a new question on this same subject.

Because date and time are invariably linked, I have to create new boundaries for each specific day of the year. Is there a way for me to set time boundaries, but not specify a date?
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,966
Messages
5,514,466
Members
409,004
Latest member
galbert

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top