Add up random time in a specific time range ?

mizzoh

New Member
Joined
Aug 29, 2022
Messages
7
Office Version
  1. 2021
Platform
  1. Windows
Hello everyone,

I have a cell A1 where I generate a random Date+time which is between the time 8:00 - 18:00 :

Excel Formula:
=RANDBETWEEN(DATE(2019,1,1),DATE(2022,12,31))+RANDBETWEEN(TIME(8,0,0)*10000;TIME(18,0,0)*10000)/10000

Let's say it results in : 29.05.2022 11:52:05

After that, in cell A3 I would like to add up a few hours randomly:
Excel Formula:
A2+RANDBETWEEN(1,60)/24

It works fine, but it is not in the time frame of 08:00 - 18:00
How am I able to achieve this?

Best regards
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi & welcome to MrExcel.
How about
Excel Formula:
=A2+RANDARRAY(1,,TIME(8,0,0),TIME(18,0,0))
 
Upvote 0
Hi, thank you for the fast reply.
I've tried it but for some reason it still gives me values between 00:00 and 23:59.
 
Upvote 0
If you start with 29.05.2022 11:52:05 and add 9 hours you will get 29.05.2022 20:52:05 which is outside your criteria.
 
Upvote 0
If you start with 29.05.2022 11:52:05 and add 9 hours you will get 29.05.2022 20:52:05 which is outside your criteria.
Yes, that is correct. This is the result for the first cell. For the second cell I'm searching for a way to make sure Excel only adds up a few hours or minutes if the result will be between 8:00 - 18:00.

A2 from first forumla:
29.05.2022 11:52:05

A3 from second formula:
it should result (e.g.) 29.05.2022 14:55:09 but not something like 29.05.2022 21:43:08
 
Upvote 0
Ok, how about
Excel Formula:
=A2+RANDARRAY(1,,0,TIME(18,0,0)-MOD(A2,1))
 
Upvote 0
Ok, how about
Excel Formula:
=A2+RANDARRAY(1,,0,TIME(18,0,0)-MOD(A2,1))
This works fine. Thanks !
May I ask you if it's possible that I add up a few hours which will be randomly in the next day or even the day after next?

so for instance it would look like this:

A2 from first forumla:
29.05.2022 11:52:05

A3 from your second formula:
it should result (e.g.) 29.05.2022 14:55:09

A4:
30.05.2022 10:11


So basically, that it would add a random amount of minutes between 1 and 1440 (1 day) but would also have a look on the range 8:00 - 18:00


Big thank you so far! I've learned a lot!
 
Upvote 0
How about
Excel Formula:
=A2+RANDARRAY(1,,0,TIME(18,0,0)-MOD(A2,1))+RANDBETWEEN(1,10)
 
Upvote 0
Solution
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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