note 107555 deleted from function.date-diff by tularis

From: Date: Sat, 18 Feb 2012 13:25:38 +0000
Subject: note 107555 deleted from function.date-diff by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-186209@lists.php.net to get a copy of this message
Note Submitter: maniarpratik at gmail dot com ---- This function will useful for counting sunday between two dates. I had used here native functions of PHP function CountSunday($from,$to) { $from=date('d-m-Y',strtotime($from)); //convert to format 'd-m-Y' for Example (18-04-1989) $to=date('d-m-Y',strtotime($to)); //convert to format 'd-m-Y' for Example (18-05-1989) $cnt=0; //used for count sunday $nodays=(strtotime($to) - strtotime($from))/ (60 * 60 * 24); // Count total no.s of days between inputed dates $nodays=$nodays+1; //add one extra day for exact counting for($i=0;$i<$nodays;$i++) { $p=0; list($d, $m, $y) = explode("-",$from); $datetime = strtotime("$d-$m-$y"); $nextday = date('d-m-Y',strtotime("+1 day", $datetime)); //Add one day in from date if($i==0) $p=date('w',strtotime($from)); //it will return which day in numeric form from , from date else $p=date('w',strtotime($nextday));//it will return which day in numeric form from , nextday if($p==0) $cnt++; $from=$nextday; $p++; } return $cnt; }

« previous php.notes (#186209) next »