I've recently run into a problem with the # of weeks calculation in an application I use. We are working with courses where the course end date crosses a calendar year - for example I have course with a start date of 11/28/2009 and an end date of 1/9/2010. When those dates are brought into the application, the integration chokes. It appears to be ignoring the year and when it calculates the course weeks it gets a negative number.
I can see that the logic to set the # of weeks for the course is taking the end week and subtracting the start week, apparently without regard for the year. So, 2-52 produces a negative number. How do I modify this to also acknowledge the year and correctly calculate the # of weeks?
if(!empty($CFG->enrol_enddate)){
// Convert dates to UNIX time
$arr_startdate = date_parse($course->startdate);
$starttime = mktime(0,0,0,$arr_startdate['month'],$arr_startdate['day'],$arr_startdate['year']);
$arr_enddate = date_parse($course->enddate);
$endtime = mktime(0,0,0,$arr_enddate['month'],$arr_enddate['day'],$arr_enddate['year']);
//Set number of Weeks in a course
$course->numsections = date('W',$endtime)-date('W',$starttime)+1;
}
$course->startdate = $starttime;
Thanks!