help me with this date code

this is my code, i have the startDate and endDate
my problem is the endDate, it will generate greater than January 2008

try this code:

<?php function dateDiff($interval,$dateTimeBegin,$dateTimeEnd) { //Parse about any English textual datetime //$dateTimeBegin, $dateTimeEnd $dateTimeBegin=strtotime($dateTimeBegin); if($dateTimeBegin === -1) { return("..begin date Invalid"); } $dateTimeEnd=strtotime($dateTimeEnd); if($dateTimeEnd === -1) { return("..end date Invalid"); } $dif=$dateTimeEnd - $dateTimeBegin; switch($interval) { case "s"://seconds return($dif); case "n"://minutes return(floor($dif/60)); //60s=1m case "h"://hours return(floor($dif/3600)); //3600s=1h case "d"://days return(floor($dif/86400)); //86400s=1d case "ww"://Week return(floor($dif/604800)); //604800s=1week=1semana case "m": //similar result "m" dateDiff Microsoft $monthBegin=(date("Y",$dateTimeBegin)*12)+ date("n",$dateTimeBegin); $monthEnd=(date("Y",$dateTimeEnd)*12)+ date("n",$dateTimeEnd); $monthDiff=$monthEnd-$monthBegin; return($monthDiff); case "yyyy": //similar result "yyyy" dateDiff Microsoft return(date("Y",$dateTimeEnd) - date("Y",$dateTimeBegin)); default: return(floor($dif/86400)); //86400s=1d } } $startDate = "January 01, 2007"; $endDate = "January 01, 2008"; $xx = dateDiff("d",$startDate,$endDate)+1; for($ii=0;$ii<=$xx;$ii++) { echo date("F d, Y",strtotime($startDate." +$ii month"))."
"; } ?>

i guess u mean that it is displaying february as well?

$xx = dif +1 = 13

$ii <= 13

so the last value is 13 month later.

either use +1 or <= instead of <, but both will result in one more month than needed.

got it dude
instead using this code:

$xx = dateDiff(“d”,$startDate,$endDate)+1;

i use

$xx = dateDiff(“m”,$startDate,$endDate)+1;

im so very clumsy in that part whew!!!

thank you very much phphelp.com and staff

Sponsor our Newsletter | Privacy Policy | Terms of Service