Taking randomly generated times, Returning "Daylight", "Nighttime" within a "time frame"

Voz86

New Member
Joined
Dec 9, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

I have a column of randomly generated times using: =TEXT(RAND()*(23-10)/24+11/24,"HH:MM"). In the next column, using this formula, =IF(AND(F4>=1200,F4<=1800), "Daylight","Nighttime")
I want to see if the random time falls between a "time window" and return "Daylight" or "Nighttime." I can't get it to work, I also tried using "TIMEVALUE"

Any guidance would be greatly appreciated!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Ideally, you want to keep it as number and just format the cell. Try
Book1
AB
1
220:31Nighttime
3
Sheet9
Cell Formulas
RangeFormula
A2A2=RAND()*(23-10)/24+11/24
B2B2=IF(AND(A2>=0.5,A2<=0.75),"Daylight","Nighttime")
 
Upvote 0
Thanks for the response. How can I incorporate TIMEVALUE if I don't change TEXT(RAND) etc?

Thanks
 
Upvote 0
It's not necessary but if that's what you prefer
Book1
AB
1
211:42Nighttime
3
Sheet9
Cell Formulas
RangeFormula
A2A2=TEXT(RAND()*(23-10)/24+11/24,"HH:MM")
B2B2=IF(AND(--A2>=TIMEVALUE("12:00"),--A2<=TIMEVALUE("18:00")),"Daylight","Nighttime")
 
Upvote 0
Awesome, that works! Final Q, why the -- before the cell number?
 
Upvote 0
"--" converts the text number to an actual number. See the example below.

Book1
ABCD
1ValuesIs Text?Formulas for Column AFormulas for Column B
222TRUE="22"=ISTEXT(A2)
322FALSE=--A2=ISTEXT(A3)
Sheet1
Cell Formulas
RangeFormula
A2A2="22"
B2:B3B2=ISTEXT(A2)
C2:D3C2=FORMULATEXT(A2:A3)
A3A3=--A2
Dynamic array formulas.
 
Upvote 0
I'm using a different formula but you don't need TIMEVALUE at all, you can use -- on all of them, but I prefer not having to do all these conversions as was suggested before.

=IF(MEDIAN(--A1,--"12:00",--"18:00")=--A1,"Daylight","Nighttime")

and with CUBIST's formula:
=IF(AND(--A1>=--"12:00",--A1<=--"18:00"),"Daylight","Nighttime")
 
Upvote 0

Forum statistics

Threads
1,224,701
Messages
6,180,443
Members
452,985
Latest member
Hai Quynh

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
Back
Top