- explode: documentation ( source)
- define: documentation ( source)
<?php
define("EVENT_YEAR",2000);
function getInterval( $strDate ){
list( $year,,) = explode( '-', $strDate );
return ($year - EVENT_YEAR);
}
$strDate = '2017-05-05';
$interval = getInterval( $strDate );
try {
$date = new DateTime( "$strDate -$interval years" );
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}
if ( $date->format("Y-m-d") == '2000-05-05') {
echo "\nThe interval is $interval years.";
}