Skip to content

Instantly share code, notes, and snippets.

@lomotech
Created September 27, 2018 04:49
Show Gist options
  • Save lomotech/a5767aea19215308a424d4dc983e8ef2 to your computer and use it in GitHub Desktop.
Save lomotech/a5767aea19215308a424d4dc983e8ef2 to your computer and use it in GitHub Desktop.
get date diff exclude multiple day
use Carbon\Carbon;
$dt = Carbon::create(2018, 9, 17);
$dt2 = Carbon::create(2018, 9, 24);
$holiday = ['2018-09-21'];
$offday = ['2018-09-22', '2018-09-21'];
$daysForExtraCoding = $dt->diffInDaysFiltered(function(Carbon $date) use ($holiday, $offday){
return !in_array($date->toDateString(), $offday) && !in_array($date->toDateString(), $holiday);
}, $dt2);
dd($daysForExtraCoding);
return $daysForExtraCoding;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment