I need to check if two dates over lap with another two dates in my database.
My database looks like this
+----+--------------+------------+------------+
You can cover all date overlapping cases even also when toDate
in database can possibly be null as follows:
SELECT * FROM `tableName` t
WHERE t.`startDate` <= $toDate
AND (t.`endDate` IS NULL OR t.`endDate` >= $startDate);
This will return all records that overlaps with the new start/end dates in anyway.