<?php
// query this in a select
$result = [
'2018/04/12 00:05',
'2018/04/12 00:15',
'2018/04/12 00:20',
];
// define start/end by first and last items in array
$begin = DateTime::createFromFormat('Y/m/d H:i', min($result));
$end = DateTime::createFromFormat('Y/m/d H:i', max($result));
$interval = new DateInterval('PT5M'); // plus time 5 min
$daterange = new DatePeriod($begin, $interval ,$end);
// build an array to compare it with
foreach ($daterange as $date){
$range[] = $date->format("Y/m/d H:i");
}
// array diff out the differences
print_r(array_diff($range, $result))
?>
1条答案
按热度按时间uurv41yg1#
你应该修好
0:
因为它不是有效的小时值。您可以像下面那样使用datetime来完成,但是您需要定义开始值和结束值,我假设您是在选择“fecha”数据时这样做的。
https://3v4l.org/fawey
结果: