Advertisement
Guest User

03. Working Days

a guest
Aug 21st, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2. $from = $_GET['dateOne'];
  3. $to = $_GET['dateTwo'];
  4. $holidays = preg_split("/\s+/", $_GET['holidays'], -1, PREG_SPLIT_NO_EMPTY);
  5.  
  6. //$from = '17-12-2014';
  7. //$to = '31-12-2014';
  8. //$holidays = array('31-12-2014', '24-12-2014', '08-12-2014');
  9.  
  10. $workdays = array();
  11. for ($currDate = date("d-m-Y", strtotime($from)); $currDate < date("d-m-Y", strtotime($to)); $currDate = date("d-m-Y", strtotime($currDate . ' + 1 days'))) {
  12.     if (date('N', strtotime($currDate)) != 6 && date('N', strtotime($currDate)) != 7) {
  13.         foreach ($holidays as $holiday) {
  14.             if (date('d-m-Y', strtotime($currDate)) != date('d-m-Y', strtotime($holiday))) {
  15.                 $workdays[] = date('d-m-Y', strtotime($currDate));
  16.             }
  17.         }
  18.     }
  19. }
  20. echo '<ol>' . "\n";
  21. foreach (array_unique($workdays) as $day) {
  22.     echo '<li>' . $day . '</li>' . "\n";
  23. }
  24. echo '</ol>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement