1 回答

TA貢獻1998條經驗 獲得超6個贊
我會使用簡單的時間戳,而不是DateTime對象。
$stmt1 = $db->query('SELECT StartTime, EndTime FROM records');
$periods = [];
while ($row = $stmt1->fetch()){
echo '<li>'.$row['StartTime'].' - '.$row['EndTime'].'</li>';
$periods[] = [strtotime($row['StartTime']), strtotime($row['EndTime'])];
}
echo "<br>";
if (isset($_POST['submit'])){
//Date validations
$inputTime = strtotime($_POST['inputTime']);
$exists = false;
foreach ($periods as $period) {
if ($inputTime >= $period[0] && $inputTime <= $period[1]) {
$exists = true;
break;
}
}
if ($exists) {
echo "This hour already exists!";
}
}
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報