I have this in my db:
I want to display doctor available time in in select box with difference of 20 minutes like from
2015-10-12 02:00:00 to 2015-10-12 04:00:00 what i need is
02:00:00
02:20:00
02:40:00
03:00:00
03:20:00
03:40:00
04:00:00
I tried this select '2015-10-12 02:00:00' + INTERVAL 20 MINUTE
but it shows only one values i need all possible combinations.
User DateTime()
, DateInterval()
, and DatePeriod()
to loop through that date period every 20 minutes and output the time. Note, we have to add a minute to the end time because DatePeriod
does not include the last end time by default. Adding that minute will get the last time to be included.
$start = new DateTime('2015-10-12 02:00:00');
$end = (new DateTime('2015-10-12 04:00:00'))->modify('+1 minute');
$interval = new DateInterval('PT20M');
$period = new DatePeriod($start, $interval, $end);
foreach($period as $date) {
echo $date->format('H:i:s');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.