Reputation: 16793
At the moment I am checking if(!is_null($foo))
although this is breaking when the mysql column is a date and defaults to 0000-00-00.
Is there any way to get around this problem without adding != "0000-00-00"
Upvotes: 3
Views: 4080
Reputation: 607
If you do not want to solve it in code, solve it in the data.
You should let MySQL default to NULL
not 0000-00-00
Upvotes: 3
Reputation: 3165
I guess you can use something like this:
if(!(int)$foo)
{
echo ' this is either a default value or a NULL';
}
Upvotes: 0
Reputation: 3679
Change your table definition for the date column
`date` DATE NULL DEFAULT NULL
I always suggest to allow NULL
for optional fields and to soundly distinguish between valid values like 0
and empty strings on the one hand and NULL
(=not stated) on the other hand.
Upvotes: 1
Reputation: 3163
For date fields you can use strtotime. This function returns false
if the date
passed to it is not a date
.
I am not sure about your specific needs as there is very little info in your question.
Upvotes: 2