How To Get All Dates Between Two Dates In Php?

PHP

Nicesnippets

886

07-01-2021


Hi Guys,

In this tutorial,I will learn you how to get all dates betweem two dates in php.you can easy and simply get all dates betweem two dates in php.

In this example,use date interval class which stores fixed amount of time (in years, months, days, hours etc) or relative time string in the format that DateTime.

Example:


<?php

$array = array();

$period = new DatePeriod(

new DateTime('2010-10-01'),

new DateInterval('P1D'),

new DateTime('2010-10-05')

);

foreach ($period as $key => $value) {

$Store = $value->format('Y-m-d');

$array[] = $Store;

}

print_r($array);

?>

Output:

Array ( [0] => 2010-10-01 [1] => 2010-10-02 [2] => 2010-10-03 [3] => 2010-10-04 )

It will help you...