I'm querying some data from MySQL database using the Laravel framework. I will not be posting the entire query as it's quite long.
$logs = DB::query('SELECT ... FROM .. JOIN ... WHERE .. GROUP BY .. ORDER BY');
I'm iterating through the results using a simple foreach loop and generating a report using PHPExcel as follows:
foreach($logs as $log):
...
endforeach;
Inside the loop, I am calculating the difference between the two dates in month as follows:
$cntr_startdate = new DateTime($log->start_date);
$cntr_enddate = new DateTime($log->end_date);
$conterm = $cntr_enddate->diff($cntr_startdate);
$cterm = (($conterm->format('%y') * 12) + $conterm->format('%m'));
After the following line, the rate field in $log object is somehow corrupted and returns garbage like b, X, and O.5 (the remaining fields are untouched).
$cterm = (($conterm->format('%y') * 12) + $conterm->format('%m'));
What could be causing the loss of data?