Rahul Pamnani
Rahul Pamnani

Reputation: 1435

I want to show time interval of 30 minutes/

I am working on doctor appointment system ,In which doctor will first enter its start time and close time like 10:00 am to 6:00 pm.If user wants the doctor appointment it will book according.I want to show timing by the interval of 30 minutes.like 10:00 - 10:30 , 10:30-11:00.upto end time.It will select start time and end time from the database. How can i do this?

Upvotes: 0

Views: 2723

Answers (2)

Naresh Kumar P
Naresh Kumar P

Reputation: 4210

You have to use strtotime in order to achieve what you want.

$starttime = '9:00';  // your start time
$endtime = '21:00';  // End time
$duration = '30';  // split by 30 mins

$array_of_time = array ();
$start_time    = strtotime ($starttime); //change to strtotime
$end_time      = strtotime ($endtime); //change to strtotime

$add_mins  = $duration * 60;

while ($start_time <= $end_time) // loop between time
{
   $array_of_time[] = date ("h:i", $start_time);
   $start_time += $add_mins; // to check endtie=me
} 

Output can be obtained using the belo code.

echo '<pre>';
print_r($array_of_time);
echo '</pre>';

Output for the above code will be like this.

Array
(
    [0] => 09:00
    [1] => 09:30
    [2] => 10:00
    [3] => 10:30
    [4] => 11:00
    [5] => 11:30
    [6] => 12:00
    [7] => 12:30
    [8] => 01:00
    [9] => 01:30
    [10] => 02:00
    [11] => 02:30
    [12] => 03:00
    [13] => 03:30
    [14] => 04:00
    [15] => 04:30
    [16] => 05:00
    [17] => 05:30
    [18] => 06:00
    [19] => 06:30
    [20] => 07:00
    [21] => 07:30
    [22] => 08:00
    [23] => 08:30
    [24] => 09:00
)

Upvotes: 3

Patrick Mlr
Patrick Mlr

Reputation: 2965

Pseudocode:

do connection to database
get result from database with start and endtime

new array

while startTime is not equal to endTime
    startTime + 30 minutes

    insert into array startTime 
while end

generate selectbox with array values

show selectbox

This is how you could do it.

Upvotes: 0

Related Questions