note 65809 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 11 Jun 2006 11:46:59 +0000 |
| Subject: | note 65809 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114269@lists.php.net to get a copy of this message | ||
Note Submitter: james at designsolution dot co dot uk
----
<?php
// calculates the number of 'business days' between two given dates
function business_day_diff( $start_date, $end_date ) {
// dates can be in any format accepted by the strtotime function
// convert to UNIX timestamps
$start_date = strtotime( $start_date );
$end_date = strtotime( $end_date );
$business_days = 0;
if ( $start_date < $end_date ) {
$date1 = $start_date;
$date2 = $end_date;
}
else {
$date1 = $end_date;
$date2 = $start_date;
}
while ( $date1 <= $date2 ) {
$thedate = getdate( $date1 );
// Skip Saturday and Sunday.
if (($thedate["wday"] != '0') and ($thedate["wday"] !=
'6')) {
$business_days++;
}
$date1 += 86400; // Add 1 day.
}
return ( $business_days );
}
?>