I am trying to edit the following script to generate a unique time between
00:00:01 and 01:30:00
Using the following script.
$start = new Datetime('00:00:01');
$end = new Datetime('01:30:00');
$randomTime = function (DateTime $start, DateTime $end, $resolution = 1) {
if ($resolution instanceof DateInterval) {
$interval = $resolution;
$resolution = ($interval->m * 2.62974e6 + $interval->d) * 86400 + $interval->h * 60 + $interval->s;
}
$startValue = floor($start->getTimestamp() / $resolution);
$endValue = ceil($end->getTimestamp() / $resolution);
$random = mt_rand($startValue, $endValue) * $resolution;
return new DateTime('@' . $random);
};
echo $random = $randomTime($start, $end, 60);
When I run the script I get the follwing error message
"Catchable fatal error: Object of class DateTime could not be converted to string"