Helper::getDateForAge PHP Метод

getDateForAge() публичный статический Метод

If given a date of death, and they will never reach the age, returns null.
public static getDateForAge ( $dob, $age, null $date_of_death = null ) : null | string
$dob
$age
$date_of_death null
Результат null | string
    public static function getDateForAge($dob, $age, $date_of_death = null)
    {
        if (!$dob) {
            return;
        }
        $dob_datetime = new DateTime($dob);
        $age_date = $dob_datetime->add(new DateInterval('P' . $age . 'Y'));
        if ($date_of_death) {
            $dod_datetime = new DateTime($date_of_death);
            if ($dod_datetime < $age_date) {
                return;
            }
        }
        return $age_date->format('Y-m-d');
    }

Usage Example

Пример #1
0
 /**
  * Returns the date on which the patient will become an adult
  *
  * @return null|string
  */
 public function getBecomesAdultDate()
 {
     return Helper::getDateForAge($this->dob, isset(Yii::app()->params['child_age_limit']) ? Yii::app()->params['child_age_limit'] : self::CHILD_AGE_LIMIT);
 }
All Usage Examples Of Helper::getDateForAge