view raw
bernte bernte - 7 months ago 34
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 "
" to keep it working in the next year.
Is it possible to add for the
the actually year?

Something like:

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



Try this,

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