Hey.
I am trying to make a pretty advance IF statement and I have just ended up with a big headache trying to understand how IF statements work in Excel.
I am basically trying to say if its during the night (22.00 - 06.59) or during the day (07.00-21:59) so I use the HOUR formula to convert my time to a number between 0 and 23 and this works fine.
However i have a start time (x) and end time (y) so it becomes a bit complicated.
I am basically trying to write this in excel:
//x = HOUR(H2)
//y = HOUR(I2)
IF
(x>=22 and x<=23) or (x>=0 and x<=6)
and
(y>=22 and y<=23) or (y>=0 and y<=6)
//if true write "Night" else "Day"
So if x is between 22 and 23 or 0 and 6 its during the day
but i also want to check the end time is also between these times so I do the same for y.
The problem is when I try to write this in excel.
I have come up with something like:
=IF(OR(AND
(HOUR(H2)>=22;HOUR(H2)<=23);
AND(HOUR(H2)>=0;HOUR(H2)<=6);
OR
(AND(HOUR(I2)>=22;HOUR(I2)<=23);
AND(HOUR(I2)>=0;HOUR(I2)<=6))
);"Night";"Day")
This formula works (amazingly)
But it only check x and y individually and don't compare them. It might be an easy fix from this but my head is exploding so would really appreciate some help. It probably is a way better way of solving this.
Thanks in advance.
Bookmarks