Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created October 21, 2019 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoisryosuke/e69c458887c111b0b8c0ebcd331c5478 to your computer and use it in GitHub Desktop.
Save whoisryosuke/e69c458887c111b0b8c0ebcd331c5478 to your computer and use it in GitHub Desktop.
PHP - Get number of "working" days in month (in this case, skips Sunday and Saturday or 0 and 6) -- via: https://stackoverflow.com/a/14186057/10097916
function countDays($year, $month, $ignore) {
    $count = 0;
    $counter = mktime(0, 0, 0, $month, 1, $year);
    while (date("n", $counter) == $month) {
        if (in_array(date("w", $counter), $ignore) == false) {
            $count++;
        }
        $counter = strtotime("+1 day", $counter);
    }
    return $count;
}
echo countDays(2013, 1, array(0, 6)); // 23

The date function is used in this example. Note about ignore parameter: 0 is sunday, ..., 6 is saturday.> ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment