symfony - Symfony2 Doctrine API not returning dates as they are in the database (adding timezone) -


i have api built symfony2 , doctrine.

dates stored in database without timezone modifiers (e.g. +0000). however, doctrine's ->findall() method returns dates timezone modifier attached. how ensure not happen? adding entity annotations? or maybe creating event listener modify data (seems might bit messy me though), or there way should done?

thanks

doctrine hydrates date , datetime columns standard php datetime objects.

according http://php.net/manual/en/datetime.construct.php:

if $timezone omitted, current timezone used.

this means if doctrine doesn't set timezone when hydrating object system's default timezone used. standard php behavior , can't changed doctrine.

solution:

even if dates constructed a timezone, shouldn't bother much. using datetime's format() method can display date in format want.

example: display date in 2000-02-01 23:59:59 format can do:

$entities = $repository->findall();  foreach($entities $entity){     echo $entity->mydate->format('y-m-d h:i:s'); } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -