You first need to run a SELECT on each date to find out if they match any actual records. If no records match then you skip the calculation. Something like:
$sql = $db->prepare("SELECT COUNT
FROM invoice
WHERE
DATE(invoice_date)
EQUALS ?);
$sql->bind_param('s', $minDate);
Do the same for maxdate, and if either count is zero then you have no records with that particular date.