Jenderal92

PHP 1

Dec 24th, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. <?php
  2.  
  3. function checkIfExist($fromTime, $toTime, $input) {
  4.  
  5. $fromDateTime = DateTime::createFromFormat("!H:i", $fromTime);
  6. $toDateTime = DateTime::createFromFormat('!H:i', $toTime);
  7. $inputDateTime= DateTime::createFromFormat('!H:i', $input);
  8. if ($fromDateTime> $toDateTime) $toDateTime->modify('+1 day');
  9. return ($fromDateTime <= $inputDateTime&& $inputDateTime<= $toDateTime) || ($fromDateTime <= $inputDateTime->modify('+1 day') && $inputDateTime<= $toDateTime);
  10. }
  11.  
  12. $result=checkIfExist("08:00","18:00","09:00");
  13. echo $result; // output 1 - true
  14.  
  15. ?>
Advertisement
Add Comment
Please, Sign In to add comment