bernte bernte - 1 year ago 99
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');


Answer Source

Try this,

$date = new DateTime(date('Y').'-04-07');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download