Am using 2 calenders in my form: $s=split("[/]",$date); $e=split("[/]",$datem); for($i=0;$i<=count($s);$i++) { $year1=$s[0]; $mon1=$s[1]; $day1=$s[2]; } for($i=0;$i<=count($e);$i++) { $year2=$e[0]; $mon2=$e[1]; $day2=$e[2]; } PHP: and i want to calculate how many days he choosed?? i did so echo $day=$day2-$day1; PHP: but the problem,if he choose for example From:2007/12/30 to:2008/12/09 i will have -21days can anyone help me???
You need to convert to timestamp for these things. I ain't PHP guru, but hope this helps $s = strtotime($date); // converts start days to timestamp $e = strtotime($datem); // converts end days to timestamp $tDiff = $e - $s; // calculate the difference $days = ceil($tDiff / 86400); // There are 86400 seconds in a day. ceil() rounds the fractions up, can't have decimal days echo $days; // outputs the number of days PHP: