-1

I'm looking a script that will only show salary dates that do not fall weekend.

For example 1st, 15th and last day of the month can be salary dates but if the date falls on a weekend, the next working day will be displayed.

This is what's been done so far...

<?php
date_default_timezone_set('UTC');

function firstDayOftheMonth($month){
    return date('j',mktime(1,1,1,$month,1,date('Y')));
}

function lastDayOfTheMonth($month){
    return date('j',mktime(-1,-1,-1,$month+1,1,date('Y')));
}

function daysInMonth($month){
    return cal_days_in_month($calendar, $month, date('Y'));
}

function getDay($day, $month){
    return date('l', mktime(0, 0, 0, $month, $day, date('Y')));
}

// Set year and month variables.
$months = 12;

echo "<strong>Month Name, 1st Expenses Day, 2nd Expenses Day, Salary Day</strong><br />";

// Loop through months
for($month=1; $month <= $months; $month++){
    echo "<strong>" . date('F', mktime(1, 1, 1, $month, 1, date('Y'))) . "</strong><br />";
    // Get No# days for each month of the year.
    $days = daysInMonth($month);
    // Loop through all days of the month.
    for($d=1; $d <= $days; $d++){
        // Get textual days
        $day = getDay($d, $month);
        if($d==firstDayOftheMonth($month) || $d==lastDayOfTheMonth($month) || $d==15){
            echo $d . ", " . $day . ", " . date('Y') . "<br />";
        }
    }

     echo "<hr />";
}

?>

Any help is much appreciated.

Thanks in advanced.

Richard Skinner
  • 738
  • 3
  • 10
  • 26

2 Answers2

3

You can use date('w') to get the day of the week as a number. I think 0 and 6 are Sunday and Saturday respectively.

ianbarker
  • 1,255
  • 11
  • 22
0
if(($i=date('w', $date))>=5) {
  $date = strtotime(date("Y-m-d", strtotime($date)) . "+ ".(7-$i).($==6 ? "day" : "days")); 
}
Tor P
  • 1,351
  • 11
  • 9