Advertisement
dimipan80

Working Days

Apr 28th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2. date_default_timezone_set('Europe/Sofia');
  3. $startDate = DateTime::createFromFormat('d-m-Y', $_GET['dateOne']);
  4. $endDate = DateTime::createFromFormat('d-m-Y', $_GET['dateTwo']);
  5. $holidays = preg_split('/\s+/', $_GET['holidays'], -1, PREG_SPLIT_NO_EMPTY);
  6. $workingDays = array();
  7. $date = $startDate;
  8. while ($date <= $endDate) {
  9.     $dateStr = $date->format('d-m-Y');
  10.     $dayOfWeek = $date->format('D');
  11.     if (!in_array($dateStr, $holidays) && $dayOfWeek != 'Sun' && $dayOfWeek != 'Sat') {
  12.         array_push($workingDays, $dateStr);
  13.     }
  14.  
  15.     date_add($date, date_interval_create_from_date_string('1 day'));
  16. }
  17.  
  18. $result = '<h2>No workdays</h2>';
  19. if (count($workingDays)) {
  20.     $result = '<ol>';
  21.     foreach ($workingDays as $day) {
  22.         $result .= "<li>{$day}</li>";
  23.     }
  24.     $result .= '</ol>';
  25. }
  26.  
  27. echo $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement