PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table test ( dates datetime not null ); insert into test values ('2021-11-01T00:00:00'), ('2021-11-01T01:00:00'), ('2021-11-01T02:00:00'), ('2021-11-01T05:00:00'), ('2021-11-01T06:00:00'), ('2021-11-01T07:00:00'), ('2021-11-01T08:00:00'), ('2021-11-01T13:00:00'), ('2021-11-01T14:00:00'), ('2021-11-01T15:00:00'), ('2021-11-01T16:00:00'), ('2021-11-01T17:00:00'), ('2021-11-01T18:00:00'), ('2021-11-01T19:00:00'), ('2021-11-01T20:00:00'), ('2021-11-01T21:00:00'); select * from test;
Copy Clear
Copy Format Clear
<?php use Carbon\Carbon; $now = Carbon::now()->format('d/m/Y'); printf("Today is %s\nCurrent PHP version: %s \n\n", $now, phpversion()); $query = "SELECT * FROM test"; $stmt = $pdo->query($query); $hours = range(0, 23); $missing = []; foreach ($stmt as $row) { $dateParts = explode(' ', $row[0]); $timeParts = explode(':', $dateParts[1]); var_dump($timeParts); if (!in_array($timeParts[0], $hours)) { $missing[] = $timeParts[0]; } } if (!empty($missing)) { echo 'Hours missing: ' . implode(', ', $missing); }
Show:  
Copy Clear