Fatal error: Cannot redeclare count_business_days() (previously declared in C:\AppServ\www\tracking\docs\member.php:347) in C:\AppServ\www\tracking\docs\member.php on line 347
el codigo es el siguiente
Código PHP:
<?php
// Set the default timezone to US/Eastern time:
date_default_timezone_set('US/Eastern');
// This function will count the number of business days between two dates
function count_business_days($a, $b) {
// First, sort these. We need to know which one comes first
if ($a < $b) {
$first = $a;
$second = $b;
} else {
$first = $b;
$second = $a;
}
// Break these timestamps up into their constituent parts:
$f = getdate($first);
$s = getdate($second);
// Calculate the number of business days in the first week left.
// Do this by subtracting the number of the day of the week from Friday
$f_days = 5 - $f['wday'];
// If it was Saturday or Sunday you will get a -1 or 5 but we want 0
if (($f_days == 5) || ($f_days < 0)) { $f_days = 0; }
// Do the same for the second week except count to the beginning of
// the week. However, make sure that Saturday only counts as 5
$s_days = ($s['wday'] > 5) ? 5 : $s['wday'];
// Calculate the timestamp of midday, the Sunday after the first date:
$f_sunday = mktime(12, 0, 0, $f['mon'],
$f['mday'] + ((7 - $f['wday']) % 7), $f['year']);
// And the timestamp of midday, the Sunday before the second date:
$s_sunday = mktime(12, 0, 0, $s['mon'],
$s['mday'] - $s['wday'], $s['year']);
// Calculate the full weeks between these two dates by subtracting
// them, then dividing by the seconds in a week. You need to round
// this afterwards to always ensure an even number. Otherwise
// daylight savings time can offset the calculation.
$weeks = round(($s_sunday - $f_sunday) / (3600*24*7));
// Return the number of days by multiplying weeks by 5 and adding
// the extra days:
return ($weeks * 5) + $f_days + $s_days;
}
// Try a couple of examples:
$date1 = strtotime('5/24/2007 9:13am');
$date2 = strtotime('5/31/2007 6:15pm');
// Calculate the business days between, They are: 31 & 8109
echo "<p>There are ", count_business_days($date1, $date2), " days.</p>";
?>