Need if statement on error: Call to a member function on null

I don’t know. I’ve been trying several things I think I need it something like this but this doesn’t work either.

<?php if ($_product->getSpecialToDate() = null ($_product->getSpecialToDate() = $datetox) ?><?php endif ?>

: )