I need help comparing two dates.
Before I insert I want to check to make sure no event is overlapping another. Basically their cant be two events within the same time frame.
inserting a date of july 21st 2008 to july 25th 2008 will come into conflict if someone makes an event on july 24th 2008 to july 30th 2008.
Right now I have:
<?php
if(isset($_POST['add'])) {
$begdate_m = $_POST['begdatem'];
$begdate_d = $_POST['begdated'];
$begdate_y = $_POST['begdatey'];
$enddate_m = $_POST['enddatem'];
$enddate_d = $_POST['enddated'];
$enddate_y = $_POST['enddatey'];
$startdate = $begdate_y."-".$begdate_m."-".$begdate_d;
$enddate = $enddate_y."-".$enddate_m."-".$enddate_d;
$startdate = strtotime($startdate);
$enddate = strtotime($enddate);
$add = true;
$query = mysql_query("SELECT * FROM de_featuredevent") or die(mysql_error());
while($row = mysql_fetch_array($query))
{
$sql = mysql_query("SELECT * FROM de_featuredevent WHERE '$startdate' OR '$enddate' BETWEEN '$row[start_date]' AND '$row[end_date]'") or die(mysql_error());
echo "SELECT * FROM de_featuredevent WHERE '$startdate' OR '$enddate' BETWEEN '$row[start_date]' AND '$row[end_date]'";
$num = mysql_num_rows($sql);
if($num == 0)
{
//If their is none found do this
echo " = timing ok<br>";
}
else
{
echo " = time mismatch<br>";
$add = false;
}
}
if($add == false)
{
echo "not adding";
}
else
{
echo "adding";
}
}
?>
I have two dates in the database right now:
Jan 2 - Jan 5
&
Jan 7 - Jan 10
If I try any date ie: Jan 15 - Jan 20 with all my echos above I get this:
SELECT * FROM de_featuredevent WHERE '1200373200' OR '1200805200' BETWEEN '1199250000' AND '1199509200' = time mismatch
SELECT * FROM de_featuredevent WHERE '1200373200' OR '1200805200' BETWEEN '1199941200' AND '1200373200' = time mismatch
not adding
Both of the integrers are not between any of those values…It makes no sense…
So my issue is with my $sql…I have to be doing something wrong here. My logic isnt right or something.
I am using the UNIX timestamp by the way.