Answers for "laravel get if two dates has 7 days difference between"

PHP
1

how to calculate date difference between two dates in laravel

//How to calculate date different between two dates in larevel
// METHOD-1
$date1 = new DateTime("2018-01-10 00:00:00");
$date2 = new DateTime("2019-05-18 01:23:45");
$difference = $date1->diff($date2);
$diffInSeconds = $difference->s; //45
$diffInMinutes = $difference->i; //23
$diffInHours   = $difference->h; //8
$diffInDays    = $difference->d; //21
$diffInMonths  = $difference->m; //4
$diffInYears   = $difference->y; //1

//or get Date difference as total difference
//METHOD-2
$d1 = strtotime("2018-01-10 00:00:00");
$d2 = strtotime("2019-05-18 01:23:45");
$totalSecondsDiff = abs($d1-$d2); //42600225
$totalMinutesDiff = $totalSecondsDiff/60; //710003.75
$totalHoursDiff   = $totalSecondsDiff/60/60;//11833.39
$totalDaysDiff    = $totalSecondsDiff/60/60/24; //493.05
$totalMonthsDiff  = $totalSecondsDiff/60/60/24/30; //16.43
$totalYearsDiff   = $totalSecondsDiff/60/60/24/365; //1.35
Posted by: Guest on March-04-2021
0

check if date between two dates laravel eloquent

//get or exist data between two dates
return Set::where('type', $type)
            ->whereDate('active_start', '<=', date("Y-m-d"))
            ->whereDate('active_end', '>=', date("Y-m-d"))
            ->first();
//@sujay
Posted by: Guest on October-15-2020

Code answers related to "laravel get if two dates has 7 days difference between"

Browse Popular Code Answers by Language