Skip to content

Instantly share code, notes, and snippets.

@erdum
Created November 16, 2023 13:08
Show Gist options
  • Save erdum/1fea8a7128a8c5e7f2d5aac2357b7b20 to your computer and use it in GitHub Desktop.
Save erdum/1fea8a7128a8c5e7f2d5aac2357b7b20 to your computer and use it in GitHub Desktop.
Get working days in a month
<?php
function get_working_days($year, $month, $last_day = null) {
$total_month_days = date('t', strtotime("$year-$month-01"));
if ($last_day) {
$total_month_days = $last_day;
}
$working_days;
$sundays;
for ($day = 1; $day <= $total_month_days; $day++) {
$dayOfWeek = date('N', strtotime("$year-$month-$day"));
if ($dayOfWeek == 7) {
$sundays++;
} else {
$working_days++;
}
}
return array($working_days, $sundays);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment