I saw it somewhere here in SO, and I used it in my project. Failed to track the original post.
// function to calculate number of given day within date range function number_of_days($day, $start, $end){ $w = array(date('w', $start), date('w', $end)); return floor( ( date('z', $end) - date('z', $start) ) / 7) + ($day == $w[0] || $day == $w[1] || $day < ((7 + $w[1] - $w[0]) % 7)); } // define your dates $start = mktime(0, 0, 0, 1, 16, 2010); $end = mktime(0, 0, 0, 1, 25, 2010); // display the count echo number_of_days(0, $start, $end);
source share