note 51741 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 15 Jan 2006 12:46:11 +0000 |
| Subject: | note 51741 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101838@lists.php.net to get a copy of this message | ||
Note Submitter: bhaveshsurani at gmail dot com
----
There is functionality to calculate the difference between two dates
and get an array. I did this function to calculate any weekday between two dates. Dateformat should
be in 'DD-MM-YYYY' and Numeric representation of the day of the week is 0 (for Sunday)
through 6 (for Saturday). .
function getDayCount($fromDate, $toDate, $weekDay){
$fst = explode("-", $fromDate);
$first = date("Y-m-d", strtotime($fst[2] . "-" . $fst[1] . "-" .
$fst[0]));
$end = explode("-", $toDate);
$last = date("Y-m-d", strtotime($end[2] . "-" . $end[1] . "-" .
$end[0]));
//Initialize a today and day counter variables
$today = $first;
$dayCount = 0;
while ($today<=$last){
$today = date("Y-m-d", strtotime("+1 days", strtotime($today)));
$day = date("w", strtotime("+1 days", strtotime($today)));
if($day == $weekDay)
$dayCount++;
}
return $dayCount;
}