In Doctrine QueryBuilder, I want to find all records where a date field does not have a real date. I have found, though, that the date '0000-00-00'
is NULL, and it's also NOT NULL. In other words,
$qb->select('t')
->from(myTable, 't')
->andWhere ... some condition...
->andWhere($qb->expr()->isNull('t.myDate'));
and
$qb->select('t')
->from(myTable, 't')
->andWhere ... some condition...
->andWhere($qb->expr()->isNotNull('t.myDate'));
both include records where the value in myDate
is '0000-00-00'
.
I've considered doing something like,
$qb->select('t')
->from(myTable, 't')
->andWhere ... some condition...
->andWhere($qb->expr()->eq('t.myDate','?1'))
->setParameter(1, '0000-00-00');
but 1) that only picks up the dates that are '0000-00-00' and misses the dates that are actually null; and 2) I understand that '0000-00-00' doesn't always equal '0000-00-00'; that even though my column is a DATE type, the $qb->expr()->eq( ... ) syntax might have to include TIME characters (00:00:00).
It would be cool if Doctrine had something like notWhere:
$qb->select('t')
->from(myTable, 't')
->andWhere ... some condition...
->butDefinitelyNotWhere($qb->expr()->isNull('t.myDate'));
because instead of finding all of the records where the date is NOT NULL, it finds what I'm looking for: all of the records that do not belong to the set where the date "is" NULL.