/** * get birthday and return age * * @param <type> $_brithday The brithday */ public static function get_age($_brithday) { if ($_brithday == null) { return null; } $brith_year = date("Y", strtotime($_brithday)); $brith_month = date("m", strtotime($_brithday)); $brith_day = date("d", strtotime($_brithday)); // to convert the jalali date to gregorian date if (intval($brith_year) > 1300 && intval($brith_year) < 1400) { list($brith_year, $brith_month, $brith_day) = \lib\utility\jdate::toGregorian($brith_year, $brith_month, $brith_day); if ($brith_month < 10) { $brith_month = "0" . $brith_month; } if ($brith_day < 10) { $brith_day = "0" . $brith_day; } } // get date diff $date1 = new \DateTime($brith_year . $brith_month . $brith_day); $date2 = new \DateTime("now"); $age = $date1->diff($date2); $age = $age->y; return $age; }