i have made a function which works just fine with 32-bit dates (acceptable with strtotime), but that is not scalable. i need to randomly generate peoples dates of birth, so i must use DateTime (and only <=5.2.13, to make it even more difficult) functions to generate them.
here is what i had:
public static function randomDate($start_date, $end_date, $format = DateTimeHelper::DATE_FORMAT_SQL_DATE)
{
if($start_date instanceof DateTime) $start_date = $start_date->format(DateTimeHelper::DATE_FORMAT_YMDHMS);
if($end_date instanceof DateTime) $end_date = $end_date->format(DateTimeHelper::DATE_FORMAT_YMDHMS);
// Convert timetamps to millis
$min = strtotime($start_date);
$max = strtotime($end_date);
// Generate random number using above bounds
$val = rand($min, $max);
// Convert back to desired date format
return date($format, $val);
}
so now, how can i generate a random date between two DateTimes?
thanks!