1$from = date('2018-01-01');
2$to = date('2018-05-02');
3
4Reservation::whereBetween('reservation_from', [$from, $to])->get();
1//How to calculate date different between two dates in larevel
2// METHOD-1
3$date1 = new DateTime("2018-01-10 00:00:00");
4$date2 = new DateTime("2019-05-18 01:23:45");
5$difference = $date1->diff($date2);
6$diffInSeconds = $difference->s; //45
7$diffInMinutes = $difference->i; //23
8$diffInHours = $difference->h; //8
9$diffInDays = $difference->d; //21
10$diffInMonths = $difference->m; //4
11$diffInYears = $difference->y; //1
12
13//or get Date difference as total difference
14//METHOD-2
15$d1 = strtotime("2018-01-10 00:00:00");
16$d2 = strtotime("2019-05-18 01:23:45");
17$totalSecondsDiff = abs($d1-$d2); //42600225
18$totalMinutesDiff = $totalSecondsDiff/60; //710003.75
19$totalHoursDiff = $totalSecondsDiff/60/60;//11833.39
20$totalDaysDiff = $totalSecondsDiff/60/60/24; //493.05
21$totalMonthsDiff = $totalSecondsDiff/60/60/24/30; //16.43
22$totalYearsDiff = $totalSecondsDiff/60/60/24/365; //1.35
1namespace App\Http\Controllers;
2
3use App\Mail\CheckUser;
4use App\User;
5use Carbon\Carbon;
6use Illuminate\Http\Request;
7use PDF;
8
9class TestController extends Controller
10{
11 public function index()
12 {
13 return view('welcome');
14 }
15
16 public function daily_report(Request $request)
17 {
18 $start_date = Carbon::parse($request->start_date)
19 ->toDateTimeString();
20
21 $end_date = Carbon::parse($request->end_date)
22 ->toDateTimeString();
23
24 return User::whereBetween('created_at', [
25 $start_date, $end_date
26 ])->get();
27 }
28}