What about:
$min = strtotime("47 years ago") $max = strtotime("18 years ago"); $rand_time = mt_rand($min, $max); $birth_date = date('%m/%d/%Y', $rand_time);
Basically: generate a pair of unix timestamps that represent a valid date rage, and then use these timestamps as the minimum / maximum ranges of the random number generator. You will return to int, which, as it turned out, will be used as a unix timestamp, which you can then feed into the date() format and the format you need.
This has the added benefit / side effect of allowing you to receive a randomized TIME TIME, not just a date.
source share