I am trying to write a program to dynamically add interval and find datetime between two dates in php.

I am getting Startdatetime, Enddatetime, Interval from the user.

If the
Start date is `2020-02-17 00:00:00`, end date is `2020-02-17 08:00:00`, and interval to be added to is 2hrs,

then I am trying to print all datetime ranges like

```
Array(
    [0] => 2020-02-17 00:00:00
    [1] => 2020-02-17 02:00:00
    [2] => 2020-02-17 04:00:00
    [3] => 2020-02-17 06:00:00
    [4] => 2020-02-17 08:00:00
)

```

I tried with dateperiod, but doesn't work as it gives only start & end date

```
$period = new DatePeriod(
    new DateTime($from_datetime),
    new DateInterval('PT$hoursH'),
    new DateTime($to_datetime)
);

```

Please help me to get all datetime ranges.