Comparison between two intervals - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Comparison between two intervals.php
- <?php
- // Time Test
- $nowTime = time();
- $time1 = date('H:i:s', strtotime($nowTime));
- $time2 = date('H:i:s', strtotime('05:30'));
- // Day interval
- $dayStartStr = date('H:i:s', strtotime('06:00:00'));
- $dayStartInt = DateTime::createFromFormat('Y-m-d H:i:s', $dayStartStr);
- $dayEndStr = date('H:i:s', strtotime('+1 day', strtotime('21:59:00')));
- $dayEndInt = DateTime::createFromFormat('Y-m-d H:i:s', $dayEndStr);
- // Night interval
- $nightStartStr = date('H:i:s', strtotime('05:59:00'));
- $nightStartInt = DateTime::createFromFormat('Y-m-d H:i:s', $nightStartStr);
- $nightEndStr = date('H:i:s', strtotime('+23 hour 59 minutes 59 seconds', strtotime('22:00:00')));
- $nightEndInt = DateTime::createFromFormat('Y-m-d H:i:s', $nightEndStr);
- /*$interval = $nightStartInt->diff($nightEndInt);
- $total = $interval->format("%H:%I");
- echo $total;*/
- if($time2 >= $dayStartStr && $time2 <= $nightStartInt) {
- echo 'First interval!';
- } else if ($time2 >= $nightStartStr && $time2 <= $dayStartInt) {
- echo 'Second interval!';
- }
- ?>
File Description
- Comparison between two intervals
- PHP Code
- 13 Jan-2020
- 1.27 Kb
You can Share it:
Latest PHP Pastes