Is there a PHP function to test a zero date
I think you don't need any shorthand.
It's sort of some micro-optimization.
You have already spent more time asking this question than can save you such a shorthand in a year of average coding. Just write it and move on.
Don't you have more important problems to solve?
Moreover, with such a shorthand you will obfuscate your own code.
Your current statement is perfectly clear, reads "if date is empty"
but all proposed snippets aren't that clear. Coming to this code months later, you will puzzle yourself with question, if such a code monster have any special meaning.
What you actually wanted is readability. But you have it already. While all proposed shorthands don't.
Although you should probably use NULL in your database, a simple hack would be:
if(!(int)$row['this_date'])echo'No Date Set.';
What kind of better way are you expecting to find? it's fast as it is.
P.S. It's a hack because I'm assuming you will have a year set. Meaning it won't work for the string 0000-00-00 00:00:01
Being a fan of regular expressions, I'll add another one:
if (!preg_match('/[1-9]/', $row['this_date'])) echo 'No date set.';
- Works also with timestamps and other stuff.
- Obviously does not check for date consistency.
What about:
if(strtotime($row['this_date']) == 0) echo 'No date set.';