Hi i know its may be difficult to get the time intervals for preparing doctor appointment slots or School Class Periods schedule..
To overcome this problem the below is php function to generate time slots which gives output as shown below picture..
<?php
function time_slots($from,$to,$interval){
$arr = array();
$start = strtotime($from);
$in = $interval*60;
$end = strtotime($to)-$in;
$time = strtotime("+0 minutes", $start);
//echo date('h:i A', $time); echo "<br />";
$arr[]=date('h:i A', $time);
for($i=$start;$i<$end;$i=$i+$in)
{
if($i >= $start && $i <= $end-$in) {
$time = strtotime("+".$interval." minutes", $i);
$arr[]=date('h:i A', $time);
//echo date('h:i A', $time); echo "<br />";
}
}
return $arr;
}
?>
Example Usage :
<?php
echo timings("04:00 AM","5:00 AM","10");
?>
To overcome this problem the below is php function to generate time slots which gives output as shown below picture..
<?php
function time_slots($from,$to,$interval){
$arr = array();
$start = strtotime($from);
$in = $interval*60;
$end = strtotime($to)-$in;
$time = strtotime("+0 minutes", $start);
//echo date('h:i A', $time); echo "<br />";
$arr[]=date('h:i A', $time);
for($i=$start;$i<$end;$i=$i+$in)
{
if($i >= $start && $i <= $end-$in) {
$time = strtotime("+".$interval." minutes", $i);
$arr[]=date('h:i A', $time);
//echo date('h:i A', $time); echo "<br />";
}
}
return $arr;
}
?>
Example Usage :
<?php
echo timings("04:00 AM","5:00 AM","10");
?>
0 comments:
Post a Comment