
Untitled
By: a guest on
Jul 4th, 2012 | syntax:
None | size: 1.28 KB | hits: 8 | expires: Never
Create an array of business days
getWorkingDays("2008-01-01","2009-06-30");
Array
(
[0] ="2008-01-01",
[1] ="2008-01-05",
[2] ="2008-01-06",
[3] ="2008-01-07",
[4] ="2008-01-08",
[5] ="2008-01-09",
[6] ="2008-01-12",
[7] ="2008-01-13",
[8] ="2008-01-14",
...
)
date('N', $dayStamp)
<?php
function getWorkingDays($startDate, $endDate) {
$businessDays = array();
$businessDaysInWeek = range(1,5); // Only Monday to Friday
// Decompose the provided dates.
list($startYear, $startMonth, $startDay) = explode('-', $startDate);
list($endYear, $endMonth, $endDay) = explode('-', $endDate);
// Create our start and end timestamps.
$startStamp = mktime(1, 1, 1, $startMonth, $startDay, $startYear);
$endStamp = mktime(1, 1, 1, $endMonth, $endDay, $endYear);
// Check each day in turn.
for($loop=$startStamp; $loop<=$endStamp; $loop+=86400) {
if(in_array(date('N', $loop), $businessDaysInWeek)) {
// You'll also want to omit bank holidays, etc. in here.
$businessDays[] = date('Y-m-d', $loop);
}
}
return $businessDays;
}
print_r(getWorkingDays('2011-01-10', '2011-01-24'));
?>