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)