HI,
I want to calculate number of working days for the academic year between two dates like(01-06-2015 to 31-10-2015).
I saw all codes that are doing only for curtrent year.
If I want to do future years , how to do automatically,
Here is my code what I tried , It works for only one year, I need to calculate dynamically for future years
$beginday = date("Y-m-01");
$lastday = date("Y-m-t");
$nr_work_days = getWorkingDays($beginday, $lastday);
echo $nr_work_days;
function getWorkingDays($startDate, $endDate)
{
$begin = strtotime($startDate);
$end = strtotime($endDate);
if ($begin > $end) {
echo "startdate is in the future! <br />";
return 0;
} else {
$no_days = 0;
$weekends = 0;
while ($begin <= $end) {
$no_days++; // no of days in the given interval
$what_day = date("N", $begin);
if ($what_day > 5) { // 6 and 7 are weekend days
$weekends++;
};
$begin += 86400; // +1 day
};
$working_days = $no_days - $weekends;
return $working_days;
}
}
AntonyRayan
15
Posting Whiz in Training
Recommended Answers
Jump to PostOk, Don't use the seconds thing to calculate as it will mess up on daylight saving and leap years.
So you want all days minus all sats and suns?Many ways to do this.This is my first shot:
function getNumWeekDays($from,$to) { $dt1 = new DateTime($from); $dt2 = …
Jump to PostWhich version of php are you using?
The manual states:
days
If the DateInterval object was created by DateTime::diff(), then this is the total number of days between the start and end dates. Otherwise, days will be FALSE.
Before PHP 5.4.20/5.5.4 instead of FALSE you will receive -99999 upon …
All 6 Replies
diafol
AntonyRayan
15
Posting Whiz in Training
AntonyRayan
15
Posting Whiz in Training
diafol
AntonyRayan
15
Posting Whiz in Training
diafol
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.