Rise time of dynamic dialing for 15 minutes

I have a problem increasing the time 15 minutes to the end.

I tried it date("H:i:s", strtotime('+15 minutes', strtotime($startTime)));

. But this is not dynamic.

Here I have start and end times.

$startTime = '09:00:00';
$endTime = '11:00:00';

      

And I want to display, for example,

09:00:00

09:15:00

09:30:00

09:45:00

10:00:00

10:15:00

10:30:00

10:45:00

Thank.

+3


source to share


4 answers


Please try below code

$startTime='09:00:00';
$endTime='11:00:00';
$Times=array();
$interval=15;

while(strtotime($startTime) < strtotime($endTime))
{   
    $Times[]=$startTime;
    $startTime=strtotime("+".$interval." minutes",strtotime($startTime));
    $startTime=date('h:i:s',$startTime);    
}

      



Output

Array
(
   [0] => 09:00:00
   [1] => 09:15:00
   [2] => 09:30:00
   [3] => 09:45:00
   [4] => 10:00:00
   [5] => 10:15:00
   [6] => 10:30:00
   [7] => 10:45:00
)

      

0


source


I think using do ... while you can do this

use this code:

$startTime = '09:00:00';
$endTime = '11:00:00';
$inc = "";
do {
    $inc = date("H:i:s", strtotime('+15 minutes', strtotime($startTime)));
    $startTime = $inc;
    echo $inc."   ";
}while($inc < $endTime);

      



output:

09:15:00 09:30:00 09:45:00 10:00:00 10:15:00 10:30:00 10:45:00 11:00:00

+1


source


You can use the following codes:

<?php

$startTime = '09:00:00';
$endTime = '11:00:00';

$times = array();
$last_inc = $startTime;
while($last_inc < $endTime) {
    $times[] = $last_inc;
    $last_inc = date("H:i:s", strtotime("+15 minutes $last_inc"));
}

print_r($times);

      

Ouput:

Array
(
    [0] => 09:00:00
    [1] => 09:15:00
    [2] => 09:30:00
    [3] => 09:45:00
    [4] => 10:00:00
    [5] => 10:15:00
    [6] => 10:30:00
    [7] => 10:45:00
)

      

+1


source


You have to loop over time to generate the data you want.

$startTime = '09:00:00';
$endTime = '11:00:00';
$new_Time = $startTime;
while($new_Time < $endTime){
    $new_Time = date("H:i:s", strtotime('+15 minutes', strtotime($new_Time)));
    echo $new_Time;
    echo "<br>";
}

      

o / r

09:15:00
09:30:00
09:45:00
10:00:00
10:15:00
10:30:00
10:45:00
11:00:00

      

+1


source







All Articles