Hai folks, my date comparison does not work. pls help! <?php echo date("Y/m/d"); //above code Shows 2012/02/29 at the time of running this script. //pls keep in mind and kindly look at my below code. $date=strtotime("+5 days"); $udate="2012/3/5"; // user entered date list($y,$m,$d) = explode('/', $udate); $udate = mktime(0, 0, 0, $m, $d, $y); if ($date==$udate){ echo "yes"; }else{ echo "no"; } ?> PHP: result shows 'no'. * this month is february and finishes in 29
ooops, i just noticed that the counter is increasing every second. so now i think this code may be correct folks <?php //echo date("Y/m/d"); // SOWS 2012/02/29 at the time of running this script $date=strtotime("+5 days"); $udate="2012/3/6"; list($y,$m,$d) = explode('/', $udate); $udate = mktime(0, 0, 0, $m, $d, $y); //echo $date . "-" . $udate . "<br>"; echo $udate-$date; if ((($udate-$date) > 24*60*60) || (($udate-$date) < 0)) { //24*60*60 is the num of seconds in a day echo "no"; }else{ echo "yes"; } ?> PHP:
EDIT: Should have refreshed before responding.... Well, you are not getting hours minutes and seconds.. the $date = strtotime("+5 days"); PHP: gives you a timestamp with hours, minutes and seconds.. looks somthing like thsi 1330949208 while the $udate = mktime(0, 0, 0, $m, $d, $y); PHP: gives you something like this 1330902000 Since you are not working with hours, mins and seconds I suggest you deduct them from the $date.... I don't know how to do that, since I don't work much with dates, but I bet you can make it