How to Iterate or loop Between two Dates

Training Mode Regular Fastrack Crash
Classroom | Online
Course Description :

Solution :  Sometimes we have need to iterate loop between two dates , example we have to update data or insert data in database between two dates. In php we can easily iterate loop between date range by using date function of php datetime, dateperiod etc.

HTML CODE :

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PHP CODE :  

$begin = new DateTime($this->input->post('from'));

 $end = new DateTime($this->input->post('to'));

  $daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);

    foreach($daterange as $date)

                                 {

         echo $date->format("Y-m-d") . "<br?>";

         }

?>

Request a Demo

Whatsapp