I'm trying to get the employees that have worked for more then 6 months and how many days have passed since that day.
I've fetched the employees with six months experience using the following query:
$empsWithSixMonthsExp = Employees::whereDate('joining_date', '>=', Carbon::now()->subMonths(6))->where('status', 1)->get();
But now I want to get the date when their 6 month was fulfilled and how many days have passed since completing their 6 month mark.
Thanks!
CodePudding user response:
Here is the example for single record
$joiningDate = '05/06/2021';
$AfterSixMonthDate = \Carbon\Carbon::createFromFormat('d/m/Y',
$joiningDate)->addMonths(6);
$todaysDate = \Carbon\Carbon::now();
$daysDifferent = $todaysDate->diff( $AfterSixMonthDate)->format('%a Days');
you can dump this code
dd( $daysDifferent,$AfterSixMonthDate,\Carbon\Carbon::now());