Advertisement
Guest User

Problem2

a guest
Aug 26th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2. if (isset($_GET['dateOne'])&&isset($_GET['dateTwo'])&&isset($_GET['holidays'])) {
  3.  
  4. $dateStart = new DateTime($_GET['dateOne']);
  5. $dateEnd = new DateTime($_GET['dateTwo']);
  6. $dateEnd->modify('+1 day');
  7.  
  8. $arr = explode("\n",$_GET['holidays']);
  9. foreach ($arr as $row) {
  10. if ($row!='') {
  11. $holidays[]=new DateTime($row);
  12. }
  13. }
  14.  
  15. $diff=$dateStart->diff($dateEnd);
  16.  
  17. while ($diff->d>0) {
  18. $isHoliday=false;
  19. if (isset($holidays)) {
  20. foreach ($holidays as $holiday) {
  21. if ($holiday->format('d-m-Y')==$dateStart->format('d-m-Y')) {
  22. $isHoliday=true;
  23. }
  24. }
  25. }
  26.  
  27. if (date('l',$dateStart->getTimestamp())!='Sunday'&&date('l',$dateStart->getTimestamp())!='Saturday'&&!$isHoliday) {
  28. $workingDates[]=$dateStart->format('d-m-Y');
  29. }
  30. $dateStart->modify('+1 day');
  31. $diff=$dateStart->diff($dateEnd);
  32. }
  33.  
  34. if (isset($workingDates)) {
  35. echo '<ol>';
  36. foreach ($workingDates as $workingDate) {
  37. echo "<li>$workingDate</li>";
  38. }
  39. echo '</ol>';
  40. } else {
  41. echo '<h2>No workdays</h2>';
  42. }
  43. }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement