Time Conflict Check


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.