too long

I want to check if an event from this year is in the future or over. So i buildt this and it works.

$date = new DateTime('2016-04-07');
$now  = new DateTime();

if($date > $now) {
    echo 'future';
} else {
    echo 'past';
}

But i don't want to change every year the "2016" to keep it working in the next year. Is it possible to add for the 2016 the actually year?

Something like:

$date = new DateTime('".date('Y')."-04-07');

Thanks

Try this,

$date = new DateTime(date('Y').'-04-07');

You can try with this:

$date = date("Y")."-04-07";
$date = new DateTime($date);

Or simply:

$date = new DateTime(date("Y")."-04-07");