Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function getWorkingDays($startDate, $endDate)
- {
- $holidays = [
- "01-01-2017", // Yılbaşı
- "23-04-2017", // 23 Nisan
- "01-05-2017", // 1 Mayıs
- "19-05-2017", // 19 Mayıs
- "24-06-2017", // Ramazan Bayramı Arifesi
- "25-06-2017", // 25 Haziran Ramazan Bayramı 1.gün
- "26-06-2017", // 26 Haziran Ramazan Bayramı 2.gün
- "27-06-2017", // 27 Haziran Ramazan Bayramı 3.gün
- "15-07-2017", // 15 Temmuz
- "30-08-2017", // 30 Ağustos
- "31-08-2017", // Kurban Bayramı Arifesi
- "01-09-2017", // Kurban Bayramı 1.gün
- "02-09-2017", // Kurban Bayramı 2.gün
- "03-09-2017", // Kurban Bayramı 3.gün
- "04-09-2017", // Kurban Bayramı 4.gün
- "29-10-2017" // 29 Ekim
- ];
- $endDate = strtotime($endDate);
- $startDate = strtotime($startDate);
- $days = ($endDate - $startDate) / 86400 + 1;
- $no_full_weeks = floor($days / 7);
- $no_remaining_days = fmod($days, 7);
- $the_first_day_of_week = date("N", $startDate);
- $the_last_day_of_week = date("N", $endDate);
- if ($the_first_day_of_week <= $the_last_day_of_week) {
- if ($the_first_day_of_week <= 6 && 6 <= $the_last_day_of_week)
- $no_remaining_days--;
- if ($the_first_day_of_week <= 7 && 7 <= $the_last_day_of_week)
- $no_remaining_days--;
- } else {
- if ($the_first_day_of_week == 7) {
- $no_remaining_days--;
- if ($the_last_day_of_week == 6) {
- $no_remaining_days--;
- }
- } else {
- $no_remaining_days -= 2;
- }
- }
- $workingDays = $no_full_weeks * 5;
- if ($no_remaining_days > 0) {
- $workingDays += $no_remaining_days;
- }
- foreach ($holidays as $holiday) {
- $time_stamp = strtotime($holiday);
- if ($startDate <= $time_stamp && $time_stamp <= $endDate && date("N", $time_stamp) != 6 && date("N", $time_stamp) != 7)
- $workingDays--;
- }
- return $workingDays;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement