View Full Version : Solved: Need help with Date/Time issue.

08-21-2007, 11:30 PM
Hey gang,
I need a little help with a Date/Time issue. More specifically a time issue. I know I could do what I want using a bunch of if/then statements, but wanted to see if there was a better way to do it.

I am using a very basic approach to extracting the current computer time.


This returns the current computer time in the format of HH:MM;

I want to generate a random number between 1-11 (which I know how to do already) and add it to the above time to come up with a new time. Can someone provide some guidance as to whether there is a function or statement that accomplishes this task? If there is no function or statement, can you give some advice on how to code for this hopefully in a way that is shorter than my beginner experience level permits me to do currently.

Thanks in advance,

08-22-2007, 12:42 AM
You could just do "+(<RandomNumber>/24)" to add hours, or "+(<RandomNumber>/24/60)" to add minutes.

Bob Phillips
08-22-2007, 01:09 AM
I would use

mytime = FormatDateTime(Now + Int(24 * Rnd + 1) / 24 + Int(60 * Rnd + 1) / 24 / 60, 4)

but you might want to think about whether the generated time has to be greater than Now or not.

08-22-2007, 05:39 AM
I will give your code a try when I get back to work tonight. I am pretty sure for the purpose that I need, I am looking for a future time that would be a random number between 1-11. Thanks for the suggestion.


Bob Phillips
08-22-2007, 06:02 AM
ACtually, more sensible is

mytime = FormatDateTime(Now + Int(1440 * Rnd + 1) / 1440, 4)