dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: October 13 2005 at 15:59 | IP Logged
|
|
|
Nick,
Are you referring to timed events created on the fly from the CREATE TIMED EVENT macro command or the ph_createtimedevent function?
If so, then this can be accomplished easily enough with the existing code.
To have a timedevent happen 3 hours in the future, plus or minus ten minutes, use the following:
ph_createtimedevent(0,"YOUR MACRO ID",ph_relativedatetime(today(),169 + rand(21)))
Now you're probably wondering, how does the above function work? The ph_createtimedevent function takes 3 parameters, the first two being easy enough to understand. The third one is a datetime value for when the timedevent should fire. Since we want to fire 3 hours from the current time, plus or minus 10 minutes, we need to first convert hours to minutes. This gives us 180. Plus or minus 10 would give us 170 to 190, a twenty minute span. Since this is a random span, then we'll use the rand() function. This function takes a value and returns a random number between 1 and the value passed inclusive. So if we want a variable number of minutes between 170 and 190, then we must have a base of 169 plus a random number from 1 to 21. This gives us: 169 + rand(21). We use the ph_relativedatetime function and use the current datetime (the today() function) plus the number of minutes in the future to come up with our timed event.
This same principle can be applied to the CREATE TIMED EVENT macro command as well.
HTH,
Dave.
|