Guest User

Compile-Time Error

a guest
Aug 26th, 2014
367
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. $startDate = $_GET['dateOne'];
  3. $endDate = $_GET['dateTwo'];
  4. $holidaysText = preg_split('/\s+/', $_GET['holidays'], -1, PREG_SPLIT_NO_EMPTY);
  5. $holidays = [];
  6. $workDays = [];
  7. $start = new DateTime($startDate);
  8. $end = new DateTime($endDate);
  9. if($start > $end){
  10.     echo "<h2>No workdays</h2>";
  11.     die;
  12. }
  13. for($i = 0; $i < count($holidaysText); $i++){
  14.     $holidays[$i] = new DateTime($holidaysText[$i]);
  15. }
  16.  
  17. $counter = 0;
  18. while($start <= $end){
  19.     $currentDate = clone $start;
  20.     if(!in_array($currentDate, $holidays) &&
  21.        date( "w", $currentDate->getTimestamp()) != 6 &&
  22.        date( "w", $currentDate->getTimestamp()) != 0) {
  23.         $workDays[$counter] = $currentDate;
  24.         $counter++;
  25.     }
  26.     $start->modify("+1day");
  27. }
  28. echo "<ol>";
  29. foreach ($workDays as $workDay) {
  30.     $a = $workDay->format("d-m-Y");
  31.     echo "<li>$a</li>";
  32. }
  33. echo "</ol>";
Advertisement
Add Comment
Please, Sign In to add comment