Created
January 27, 2018 17:21
-
-
Save depsimon/22260e7106dfa961c6a37e12d0386082 to your computer and use it in GitHub Desktop.
Count mondays of a month with Carbon in PHP/Laravel
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 mondaysInMonth($month = null) { | |
if ($month === null) $month = Carbon\Carbon::today()->startOfMonth(); | |
$nextMonth = $month->copy()->endOfMonth(); | |
return $month->diffInDaysFiltered(function ($date) { | |
return $date->isMonday(); | |
}, $nextMonth); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment