code: public function getDate($params = [], $format = 'Y-m-d')
  	{
  		foreach ($params as $k => $v) {
  			$$k = $v;
  		}
  
  		if (!isset($min_year)) {
  			$min_year = date('Y') - 2;
  		}
  		
  		if (!isset($max_year)) {
  			$max_year = date('Y');
  		}
  
  		if (!isset($min_month)) {
  			$min_month = 1;
  		}
  		
  		if (!isset($max_month)) {
  			$max_month = 12;
  		}
  		
  		// Pick a random year and month within the valid ranges.
  		$rand_year	= rand($min_year, $max_year);
  		$rand_month	= rand($min_month, $max_month);
  
  		// Create a date object using the first day of this random month/year.
  		$date = DateTime::createFromFormat('Y-m-d', join('-', [$rand_year, $rand_month, '01']));
  		
  		// How many days in this random month?
  		$days_in_month = $date->format('t');
  
  		// Pick a day of the month.
  		$rand_day = rand(1, $days_in_month);
  		
  		return DateTime::createFromFormat('Y-m-d', join('-', [$rand_year, $rand_month, $rand_day]))->format($format);
  	}
docs: Generate a random date.
  @param array $params Associative array with following keys: minYear, maxYear, minMonth, maxMonth
  @param string $format date() format for return value.  Default: Y-m-d
  @return string formatted date string.