Created
November 16, 2023 13:08
-
-
Save erdum/1fea8a7128a8c5e7f2d5aac2357b7b20 to your computer and use it in GitHub Desktop.
Get working days in a month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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