Hello,
I am trying to write code for entering two dates via dropdown menus.
Date1 Month1 Year1-- Day2, Month2 Year2, and then have it loop through the database to compare item activity per day.
I'm having a problem with the date part. Through the board I was able to get close with this:
$start = strtotime('01 november 2004');
$stop = strtotime('01 december 2004');
for($i=$start;$i<=$stop;$i+=86400)
{
$sdate=date("Y-m-d", $i);
$sql9 = "SELECT itemid from table WHERE DATE_FORMAT(sdate, '%Y-%m-%d')='$sdate' AND ....etc..";
}
Which worked fine when the date was hard coded in that format. I'm not having luck with the dropdowns. This is my code:
$d1=$POST['d1'];
$m1=$POST['m1'];
$y1=$POST['y1'];
$d2=$POST['d2'];
$m2=$POST['m2'];
$y2=$POST['y2'];
$date1="$y1-$m1-$d1";
$start = date('Y-m-d', strtotime($date1));
$date2="$y2-$m2-$d2";
$stop = date('Y-m-d', strtotime($date2));
echo"Start: $start, Stop: $stop<br>";
At that point it is achoing the dates properly,..but when it gets to this:
for($i=$start;$i<=$stop;$i+=86400)
{
$sdate=date("Y-m-d", $i);
$sql9 = "SELECT itemid from table WHERE DATE_FORMAT(sdate, '%Y-%m-%d')='$sdate' AND ....etc..";
}
It fails and will echo the 1969-12-31 date for the $sdate variable. The only difference I can see betwen the two is that ("Y-m-d", is being defined twice. That may be the problem but I don't know the syntax for resolving it.
Thanks for any help.