bernte bernte - 1 month ago 4
PHP Question

DateTime with date('Y') function

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

Answer

Try this,

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