Skip to content

Instantly share code, notes, and snippets.

@depsimon
Created January 27, 2018 17:21
Show Gist options
  • Save depsimon/22260e7106dfa961c6a37e12d0386082 to your computer and use it in GitHub Desktop.
Save depsimon/22260e7106dfa961c6a37e12d0386082 to your computer and use it in GitHub Desktop.
Count mondays of a month with Carbon in PHP/Laravel
<?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