Based on your latest change, wouldn't this work:
$votedToday = ($today->format('Y-m-d') == $lastDate->format('Y-m-d'));
I agree it's kind of strange that DateTime doesn't have a method to just extract the date portion, similar to MySQL, but if you're going to use format
, why not skip the diff
and just compare the formatted date string for the full date of both DateTime objects?
And to simplify it further, you could use:
$votedToday = ($lastDate->format('Y-m-d') == date('Y-m-d'));
Assuming you are only using $today
to confirm if $lastDate
is on today.