I am having a very weird problem.
When I run my piece of code, I get an error saying $carDay->date is not an object. but when I run it in debug mode, it works fine. So I assume it is kind of a racing condition.
$trip is an object from ORM database (MySQL) and getStart-> is just a getter that gets the starting date in this format “20120929T024754”. I convert that string to a date and then do stuff with the date. But like I said when I run it without debugging the date doesn’t seem to be converted in time when I want to access it. Does anyone have anyone Idea why or what I can do about it ?
private function calculateIntLate($trip) {
$carDay = $trip->getStart();
$carDay_date = $this->convertStringToDateTime($carDay);
$carDate = $carDay_date->date;
}
public function convertStringToDateTime($string) {
//012345678901234
//20120929T024754
$year = substr($string, 0, 4);
$month = substr($string, 4, 2);
$day = substr($string, 6, 2);
$hour = substr($string, 9, 2);
$minute = substr($string, 11, 2);
$second = substr($string, 13, 2);
$dateTime = new \DateTime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second);
return $dateTime;
}
Ok,
I found the answer here.
Aparently you cant use the Datetime->date property