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
1$from = date('2018-01-01');
2$to = date('2018-05-02');
3
4Reservation::whereBetween('reservation_from', [$from, $to])->get();
5
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}
1<?php
2 //check if date between two dates
3$currentDate = date('Y-m-d');
4$currentDate = date('Y-m-d', strtotime($currentDate));
5$startDate = date('Y-m-d', strtotime("01/09/2019"));
6$endDate = date('Y-m-d', strtotime("01/10/2019"));
7if (($currentDate >= $startDate) && ($currentDate <= $endDate)){
8 echo "Current date is between two dates";
9}else{
10 echo "Current date is not between two dates";
11}
12//@sujay
1// how to get dates between two dates in laravel?
2
3//NOTE => for this you can use Carbon
4use Carbon\CarbonPeriod;
5
6$period = CarbonPeriod::create("2020-5-20", "2020-5-30");
7foreach ($period as $date) {
8 // Insert Dates into listOfDates Array
9 $listOfDates[] = $date->format('Y-m-d');
10}
11
12// Now You Can Review This Array
13dd($listOfDates);
14