src/Utility/Time.php
public static function age($start, $end = null) {
		if (empty($start) && empty($end) || $start == $end) {
			return 0;
		}

		if (is_int($start)) {
			$start = date(FORMAT_DB_DATE, $start);
		}
		if (is_int($end)) {
			$end = date(FORMAT_DB_DATE, $end);
		}

		$startDate = $start;
		if (!is_object($start)) {
			$startDate = new CakeTime($start);
		}

		$endDate = $end;
		if (!is_object($end)) {
			$endDate = new CakeTime($end);
		}

		if ($startDate > $endDate) {
			return -1;
		}
		$oDateInterval = $endDate->diff($startDate);
		return $oDateInterval->y;
	}
public static function age($start, $end = null) {
		if (empty($start) && empty($end) || $start == $end) {
			return 0;
		}

		if (is_int($start)) {
			$start = date(FORMAT_DB_DATE, $start);
		}
		if (is_int($end)) {
			$end = date(FORMAT_DB_DATE, $end);
		}

		$startDate = $start;
		if (!is_object($start)) {
			$startDate = new CakeTime($start);
		}

		$endDate = $end;
		if (!is_object($end)) {
			$endDate = new CakeTime($end);
		}

		if ($startDate > $endDate) {
			return -1;
		}
		$oDateInterval = $endDate->diff($startDate);
		return $oDateInterval->y;
	}
public static function age ( $ start , $ end = null ) { if ( empty ( $ start ) && empty ( $ end ) || $ start == $ end ) { return 0 ; } if ( is_int ( $ start ) ) { $ start = date ( FORMAT_DB_DATE , $ start ) ; } if ( is_int ( $ end ) ) { $ end = date ( FORMAT_DB_DATE , $ end ) ; } $ startDate = $ start ; if ( ! is_object ( $ start ) ) { $ startDate = new CakeTime ( $ start ) ; } $ endDate = $ end ; if ( ! is_object ( $ end ) ) { $ endDate = new CakeTime ( $ end ) ; } if ( $ startDate > $ endDate ) { return - 1 ; } $ oDateInterval = $ endDate -> diff ( $ startDate ) ; return $ oDateInterval -> y ; }
Calculates the age using start and optional end date.
Both dates default to current date. Note that start needs
to be before end for a valid result.

@param int|string $start Start date (if empty, use today)
@param int|string|null $end End date (if empty, use today)
@return int Age (0 if both timestamps are equal or empty, -1 on invalid dates)
Calculates the age using start and optional end date . Both dates default to current date . Note that start needs to be before end for a valid result .