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?
Printable View
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?
Yes, but date() doesn't have a built in check for working days.
I assume I am going to have to code and check the actual day:
if day == 6 and saturday or sunday then day++
then do a recursive loop until it equals monday-Friday?
EDIT: Ah, only Mon-Fri. You will have to do an if statement for that.
Here is a quick implementation I just wrote up. This should work for you.
PHP Code:<?php
function sixthDay($m, $y) {
$n = 0;
for ($d = 1; $d <= date('t', mktime(0, 0, 0, $m, 1, $y)); $d++) {
$tempDate = date('l', mktime(0, 0, 0, $m, $d, $y));
if ($tempDate !== 'Saturday' && $tempDate !== 'Sunday') {$n++;}
if ($n == 6) {break;}
}
return $tempDate;
}
echo sixthDay(6, 2008);
?>
Example #1 doesn't have any working day code in it ?
There is some working day code further down but only to find the number of working days in a month, which is a calculation...
We posted at the same time. Read my last post.
Perfect. Thanks very much.
I'll make some slight alterations to get the day numbers...