check if a date is between two dates laravel code example

Example 1: how to get dates between two dates in laravel

// how to get dates between two dates in laravel?

//NOTE => for this you can use Carbon
use Carbon\CarbonPeriod;

$period = CarbonPeriod::create("2020-5-20", "2020-5-30");
foreach ($period as $date) {
  // Insert Dates into listOfDates Array
  $listOfDates[] = $date->format('Y-m-d');
}

// Now You Can Review This Array
dd($listOfDates);

Example 2: check if date between two dates laravel

<?php 
  //check if date between two dates
$currentDate = date('Y-m-d');
$currentDate = date('Y-m-d', strtotime($currentDate));   
$startDate = date('Y-m-d', strtotime("01/09/2019"));
$endDate = date('Y-m-d', strtotime("01/10/2019"));   
if (($currentDate >= $startDate) && ($currentDate <= $endDate)){   
  echo "Current date is between two dates";
}else{    
  echo "Current date is not between two dates";  
}
//@sujay

Tags:

Php Example