Get next 6 days from the current date in PHP

First of all, you must know how to increment a date by PHP +1 day.

We have to run a for loop based on the range of days to echo each of the dates between the start date and end date. For example, if we want to print the dates for 6 days then the for loop will be executed upto 6 as shown below

for($i=1;$i<6;$i++)

PHP date +1 day

$date = date('Y-m-d');
$nextday = date('Y-m-d',strtotime('+1 day',strtotime($date)));

Output:- 2021-09-22 (now current date is : 2021-09-22)

Complete Code Below

$today = date('l');
  $date = date('Y-m-d'); //current date
  $weekdays = array();
  for($i =1; $i <= 6; $i++){
    $date = date('Y-m-d', strtotime('+1 day', strtotime($date)));
    $weekdays[] = date('l : Y-m-d', strtotime($date));
  }
 
  echo $today .':'. $date.'<br>';
 
  foreach($weekdays as $days){
 
      echo $days.'<br>';
  }

Leave a Reply

Your email address will not be published.