Forum Moderators: coopster

Message Too Old, No Replies

find 6th working day

         

jackvull

12:48 pm on Jun 9, 2008 (gmt 0)

10+ Year Member



Any ideas on how I can find the 6th working day of each month?
I don't want to put in a check for if Monday, else if Tuesday advance 1 day, etc. although maybe this is the only way?

supermanjnk

8:31 pm on Jun 9, 2008 (gmt 0)

10+ Year Member



if weekends are your non work days, you could try something like this.
<?
$startday = '1';
$month = '04';
$year = '2008';
$workdays = array('1','2','3','4','5');
$i = 1;
while ($i <= 6) {
$dow = date('w', mktime(0,0,0,$month,$startday,$year));
if (in_array($dow, $workdays)) {
$date = date('D m/d/Y', mktime(0,0,0,$month,$startday,$year));
$i++;
}
$startday++;
}
echo $date;
?>

g1smd

8:32 pm on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Does it need to cater for public holidays too?

cameraman

8:45 pm on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming a 5 day workweek:

$yr = 2008;
for($mon = 1; $mon < 13; $mon++) {
$first = strtotime("$yr-$mon-01");
$off = date('w',$first); // Get the day of the week as a number 0-6

// If it's 0 (Sunday) make the offset 1. If it's 6 (Saturday) make the offset 2. Otherwise, offset is zero.
$off = $off ? (($off == 6) ? 2 : 0) : 1;
$off += 7; // Add a week
$work6 = strtotime("+$off days",$first); // Offset the 1st of the month
echo "<div>" . date("D, j M Y",$work6) . "</div>\n";
}