Advertisement
Venciity

Working days 100/100 by Valeri

Aug 24th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. date_default_timezone_set("Europe/Sofia");
  3.  
  4. $start = $_GET['dateOne'];
  5. $end = $_GET['dateTwo'];
  6. $holidays = $_GET['holidays'];
  7.  
  8. $holidayArray = explode(PHP_EOL, $holidays);
  9.  
  10.  
  11. function isWeekend($day) {
  12.     $formatDay = date('w', strtotime($day));
  13.     return ($formatDay == 0 || $formatDay == 6);
  14. }
  15. $result = '<ol>';
  16. while(strtotime($start) <= strtotime($end)) {
  17.     if(!isWeekend($start) && !in_array($start, $holidayArray)) {
  18.         $result .= '<li>' . $start . '</li>';
  19.     }
  20.     $start = date("d-m-Y", strtotime("+ 1 day", strtotime($start)));
  21. }
  22. $result .= '</ol>';
  23.  
  24. if(strlen($result) == 9) { echo "<h2>No workdays</h2>";}
  25. else {echo $result;}
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement