Created
May 28, 2022 08:51
-
-
Save ephrin/ca689dbc0c41ae77846e5b2f758af4cc to your computer and use it in GitHub Desktop.
calc days of week in 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 calcDays($daysToCalc, string $firstDay, string $lastDay) | |
{ | |
$start = new \DateTime($firstDay); | |
$oneDay = new \DateInterval('P1D'); | |
$end = (new \DateTime($lastDay))->sub($oneDay); | |
$day = $start; | |
$count = 0; | |
while ($day <= $end) { | |
if (in_array((int)$day->format('w'), $daysToCalc)) { | |
$count++; | |
} | |
$day = $day->add($oneDay); | |
} | |
echo $count . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment