I too am struggling with the same type of problem.
I am currently building a time sheet system for the company I work for.
My localhost (XAMPP) I am used to test the system has no problem with the code. On my webserver the following problem occurs:
"Fatal error: Call to a member function format() on a non-object in /usr/home/ubidjak/public_html/projectway/calDate.php on line 61"
line 61 is in function with the name increments the line is: "$beginDate = $begin->format("Y/m/d");"
$begin and $end is TimeDate objects.
Is there something I can do to fix it?
function increments( $begin, $end, $inc ) {
$dates = array();
$beginDate = $begin->format("Y/m/d");
$endDate = $end->format("Y/m/d");
$dayWeekStart = calDayWeek($beginDate);//call function (not shown)
$dayWeekEnd = calDayWeek($endDate);//call function (not shown)
$dayStart=$dayWeekStart[0];
$weekStart=$dayWeekStart[1];
$monthStart= ($begin->format(m))-1;
$daysMonthStart = ($begin->format(d))-1;
$beginTest = $beginDate;
switch ($inc) {
case "Weekly": $begin = $begin->modify("-$dayStart day"); break;
case "Monthly": $begin = $begin->modify("-$daysMonthStart day"); break;
case "Yearly": $begin = $begin->modify("-$daysMonthStart day"); $begin = $begin->modify("-$monthStart month"); break;
default: break;
}
$date = $begin;
while ( $date < $end ) {
switch ($inc) {
case "Overall": {
$dates[] = $date->format("Y/m/d");
$date = $end;
$dates[] = $end->format("Y/m/d");
break;
}
case "Daily": {
$dates[] = $date->format("Y/m/d");
$dates[] = $date->format("Y/m/d");
$date = $date->modify("+1 day");
break;
}
case "Weekly": {
$dates[] = $date->format("Y/m/d");
$date = $date->modify("+6 day");
$dates[] = $date->format("Y/m/d");
$date = $date->modify("+1 day");
break;
}
case "Monthly": {
$dates[] = $date->format("Y/m/d");
$date->modify("+1 month");
$date->modify("-1 day");
$dates[] = $date->format("Y/m/d");
$date->modify("+1 day");
break;
}
case "Yearly": {
$dates[] = $date->format("Y/m/d");
$date->modify("+1 year");
$date->modify("-1 day");
$dates[] = $date->format("Y/m/d");
$date->modify("+1 day");
break;
}
default: break;
}
}
if ( $inc == "Daily" ) { $dates[] = $date->format("Y/m/d"); $dates[] = $date->format("Y/m/d"); }
$dates[0] = $beginDate;
$dates[count($dates)-1] = $endDate;
return $dates;
}