Setting condition when current time falls betwen two times

shahdelsol

Active Member
Joined
Jul 21, 2009
Messages
268
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())
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

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,895
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
268
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
268
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())
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,903
Messages
5,834,312
Members
430,276
Latest member
legalcriminal015

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