Intervale orare - 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.



Your result can be seen below.

Result of php executing





Full code of Intervale orare.php

  1. <?php
  2.  
  3.  
  4.  
  5. $time = date('Y-m-d 08:30:00');
  6.  
  7.  
  8. if($time >= date('Y-m-d 00:00:00') && $time <= date('Y-m-d 05:59:59')){
  9.     echo 'nigh interval';
  10. }
  11. if($time >= date('Y-m-d 06:00:00') && $time <= date('Y-m-d 21:59:59')){
  12.     echo 'day interval';
  13. }
  14. if($time >= date('Y-m-d 22:00:00') && $time <= date('Y-m-d 23:59:59')){
  15.     echo 'nigh interval';
  16. }
  17.  
  18.  
  19. exit;
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.             // Time Test
  30.             $nowTime = time();
  31.             $time1 = date('H:i:s', strtotime($nowTime));
  32.             $time2 = date('H:i:s', strtotime('01:30'));
  33.  
  34.             // Day interval
  35.             $dayStartStr = date('H:i:s', strtotime('06:00:00'));
  36.             //$dayStartInt = DateTime::createFromFormat('Y-m-d H:i:s', $dayStartStr);
  37.             $dayEndStr = date('H:i:s', strtotime('21:59:00'));
  38.             //$dayEndInt = DateTime::createFromFormat('Y-m-d H:i:s', $dayEndStr);
  39.  
  40.             // Night interval
  41.             $nightStartStr = date('H:i:s', strtotime('22:00:00'));
  42.             //$nightStartInt = DateTime::createFromFormat('Y-m-d H:i:s', $nightStartStr);
  43.             $nightEndStr = date('H:i:s', strtotime('05:59:00'));
  44.             //$nightEndInt = DateTime::createFromFormat('Y-m-d H:i:s', $nightEndStr);
  45.             
  46.             /*$interval = $nightStartInt->diff($nightEndInt);
  47.             $total = $interval->format("%H:%I");
  48.             echo $total;*/
  49.  
  50.             if(strtotime($time2) >= strtotime($dayStartStr) && strtotime($time2) <= strtotime($dayEndStr)) {
  51.                 echo 'Day interval!';
  52.             } else if (strtotime($time2) >= strtotime($nightStartStr) && strtotime($time2) <= strtotime($nightEndStr)) {
  53.                 echo 'Night interval!';
  54.             }
  55.             
  56. ?>
  57.  
File Description
  • Intervale orare
  • PHP Code
  • 15 Jan-2020
  • 1.64 Kb
You can Share it: