Check if two PHP datetime objects are set to the same date ( ignoring time )

Use the object syntax!

$firstDate = $firstDateTimeObj->format('Y-m-d');
$secondDate = $secondDateTimeObj->format('Y-m-d');

You were very close with your if expression, but the ! operator must be within the parenthesis.

if (!($firstDate == $secondDate))

This can also be expressed as

if ($firstDate != $secondDate)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)