Posted By

leonelsantos on 05/17/10


Tagged

php time date DateTime


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

karp13
dantreacy


Time Conflict Check


 / Published in: PHP
 

URL: http://www.kirupa.com/forum/showthread.php?t=340013

  1. /*
  2.  
  3. check if time overlaps
  4. parameters should be same date format
  5.  
  6. */
  7. function intersectCheck($from, $from_compare, $to, $to_compare){
  8. $from = strtotime($from);
  9. $from_compare = strtotime($from_compare);
  10. $to = strtotime($to);
  11. $to_compare = strtotime($to_compare);
  12. $intersect = min($to, $to_compare) - max($from, $from_compare);
  13. if ( $intersect < 0 ) $intersect = 0;
  14. $overlap = $intersect / 3600;
  15. if ( $overlap <= 0 ):
  16. // There are no time conflicts
  17. return TRUE;
  18. else:
  19. // There is a time conflict
  20. // echo '<p>There is a time conflict where the times overlap by ' , $overlap , ' hours.</p>';
  21. return FALSE;
  22. endif;
  23. }

Report this snippet  

You need to login to post a comment.