I want to get some random date and time values based on a given date range.
Ex: start date: 2015-04-29 08:00:00
and end date: 2015-04-29 20:00:00
.
Now I want to get the 15 random date and time values and also it should be in minimum 1 minute's interval.
I tried the following code:
rand_date($min_date, $max_date,$total_number);
function rand_date($min_date, $max_date,$total_number)
{
$min_epoch = strtotime($min_date);
$max_epoch = strtotime($max_date);
for($i=0;$i<=$total_number;$i++)
{
$rand_epoch = rand($min_epoch, $max_epoch);
echo "in::".date('Y-m-d H:i:s', $rand_epoch)."\n\n";
}
}
current output:
in::2015-04-29 17:41:13 //<-
in::2015-04-29 17:41:15 //<-
in::2015-04-29 15:38:39
in::2015-04-29 17:41:50 //<-
in::2015-04-29 17:45:21
in::2015-04-29 11:50:57
in::2015-04-29 19:34:12
in::2015-04-29 14:05:55
in::2015-04-29 11:25:36
in::2015-04-29 15:46:53
in::2015-04-29 14:55:44
in::2015-04-29 19:53:30
in::2015-04-29 18:28:03
in::2015-04-29 08:52:13
in::2015-04-29 17:59:42
As you can see in the above result I have highlighted a few entries in which there is only distance based on seconds, but actually I need a minimum of 1 minute's distance in all date and time values.
How can I get the code to works, so that there is a minimum interval of 1 minute between each dateTimes ?