Setting condition when current time falls betwen two times

shahdelsol

Active Member
Joined
Jul 21, 2009
Messages
266
I am trying to set up an IF formula when the current time falls between 21:00 and 23:59. I have used this formula but it is not working. If the current time is between 21:00 and 23:59, I want to get tomorrow's date but if it is passed midnight, I want to get today's date. Can anyone help?

Code:
=IF(AND(NOW()>="21:00",NOW()<="23:59"),TODAY()+1,TODAY())
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

CWatts

Well-known Member
Joined
Jan 22, 2010
Messages
701
It's because you're using text rather than time and I think any success would have been coincidental. Here's an alternative:

Code:
=TODAY()+IF(HOUR(NOW())>=21,1,0)

For yours to have worked, you'd have to had used TIMEVALUE("21:00") instead of just "21:00"
 
Last edited:

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,386
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Here's an alternative:
Code:
=IF(AND(MOD(NOW(),1)>=TIMEVALUE("21:00"),MOD(NOW(),1)<=TIMEVALUE("23:59")),TODAY()+1,TODAY())
 

shahdelsol

Active Member
Joined
Jul 21, 2009
Messages
266
Thank you for quick response. I will try it tonight.
It's because you're using text rather than time and I think any success would have been coincidental. Here's an alternative:

Code:
=TODAY()+IF(HOUR(NOW())>=21,1,0)

For yours to have worked, you'd have to had used TIMEVALUE("21:00") instead of just "21:00"
 

shahdelsol

Active Member
Joined
Jul 21, 2009
Messages
266
Thanks to you as well. I will try yours too. I like to keep both formulas.
Here's an alternative:
Code:
=IF(AND(MOD(NOW(),1)>=TIMEVALUE("21:00"),MOD(NOW(),1)<=TIMEVALUE("23:59")),TODAY()+1,TODAY())
 

Watch MrExcel Video

Forum statistics

Threads
1,122,217
Messages
5,594,887
Members
413,947
Latest member
gizmolucy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top