I know there has been a few post in stackoverflow around my question, but none of the responses seem to be working for me, and this is why I'm posting here.
I have a class with created_at and updated_at, both are expecting a datetime value
In my setter I have:
$date = new \DateTime('now');
$stimestamp = $date->format('M-d-Y H:i:s');
$this->setUpdatedAt($stimestamp);
Same error occurs when I use the following
$this->setUpdatedAt(strtotime($stimestamp));
I get the following error: Error: Call to a member function format() on string
My Oracle database is expecting the datetime as following 'DD-MON-YYYY' but doctrine is generating the query as 'Y-d-M' Which I think is the UNIX format.
How can I resolve that I can send the proper datetime value and format?
Try to use this if it can solve the issue (Of course don't forget to alter the format strings according to your locale).
$em = $this->get('doctrine.orm.default_entity_manager');
$dbh = $em->getConnection();
$sth = $dbh->prepare("ALTER SESSION SET NLS_TIME_FORMAT = 'HH24:MI:SS' NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS TZH:TZM'");
$sth->execute();
I found the solution in another post here on Stackoverflow, unfortunately I lost the link. Jan Rydrych answer was in the right path, but I didn't wanted to apply his solution on a controller class, instead I wanted to make it global.
In symfony, under services I added the following:
app/config.services.yml
oci8.listener:
class: Doctrine\DBAL\Event\Listeners\OracleSessionInit
arguments:
- { NLS_TIMESTAMP_TZ_FORMAT: "YYYY-MM-DD HH24:MI:SSTZH:TZM" }
tags:
- { name: doctrine.event_listener, event: postConnect }
The above solved the problem.
Thank you all for the help.