Laravel Carbon Count Weekends Days Between Two Dates Example
Hello,
This definitive guide, we will show you laravel carbon count weekends days between dates. we will help you to give an example of laravel carbon get difference between two dates in weekends days. This post will give you a simple example of calculate Saturday and Sunday days between two dates in laravel. This example will help you carbon difference between two dates in weekends days. Alright, let us dive into the details.
you can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.
In the following example you can see, we have two dates, the first $startDate variable and the second one $endDate variable. Carbon class diffInDaysFiltered() function using you can get the difference between two dates in weekends/holiday days. I hope you will find your solution.
Example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class DemoController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$startDate = Carbon::parse("2022-11-01");
$endDate = Carbon::parse("2022-11-21");
$days = $startDate->diffInDaysFiltered(function (Carbon $date){
return !$date->isWeekday();
}, $endDate);
dd($days);
}
}
Output
6
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Carbon Count Days Between Two Dates Example
- Laravel Carbon Parse Date Format Example
- How to Check Date is Today's Date or not in Laravel Carbon?
- Laravel Carbon Time Format AM PM Example Code
- Laravel Carbon Get Year from Date Example
- Laravel Carbon Get Previous Month Example
- Laravel Carbon Get Next Month Example
- Laravel Carbon Get All Months Between Two Dates Example
- Laravel Carbon Get All Dates Between Two Dates Example
- Laravel Carbon Get Current Date Time Example
- Laravel Carbon Subtract Seconds Example
- Laravel Carbon Subtract Days to Date Example
- Laravel Calculate Age from Date of Birth Example