note 51741 added to function.date
| From: | bhaveshsurani at gmail dot com | Date: | Sat, 09 Apr 2005 04:40:47 +0000 |
| Subject: | note 51741 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87747@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51741
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51741&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51741&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51741&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51741&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51741&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51741&report=yes
Search -- http://master.php.net/manage/user-notes.php