I think this should be simpler than my head is treating it - but I've been staring at it for too long...
I have a database driven competitions engine for a client. They can log in and upload a prize photo, question, start / end dates etc.
All works great - except they're now changing the system to allow only one competition to be running at a time. So when someone tries to add a new one I need to validate it doesn't overlap with any other competitions already in the database...
My head has managed to get me this far :
$db->query('SELECT
1
FROM
' . DB_T_PREFIX . 'competition
WHERE
(
start_date <= "'.$fldStartDate->getValue().'"
AND
close_date >= "'.$fldStartDate->getValue().'"
)
AND
deleted = "0000-00-00 00:00:00"');
Can someone sanity check me that this should cover any overlaps? I'm pretty sure I need more conditions to cover this but head has turned to mush... hate working with date ranges.
Thanks,
Steve