I have a User entity:
use DoctrineORMMapping as ORM;
/**
* ExampleBundleEntityUser
*
* @ORMEntity()
*/
class User
{
// ...
/**
* @ORMColumn(type="service_expires_at", type="date", nullable=true)
*/
private $service_expires_at;
public function getServiceExpiresAt()
{
return $this->service_expires_at;
}
public function setServiceExpiresAt(DateTime $service_expires_at)
{
$this->service_expires_at = $service_expires_at;
}
}
When i update the User's service_expires_at
as following, the updated service_expires_at
value is NOT saved back into the database:
$date = $user->getServiceExpiresAt();
var_dump($date->format('Y-m-d')); // 2013-03-08
$date->modify('+10 days');
var_dump($date->format('Y-m-d')); // 2013-03-18
$user->setServiceExpiresAt($date);
$em->persist($user);
$em->flush();
However if i pass a new DateTime
object to service_expires_at
, the updated value is saved correctly:
$date = $user->getServiceExpiresAt();
$date->modify('+10 days');
$user->setServiceExpiresAt(new DateTime($date->format('Y-m-d'));
$em->persist($user);
$em->flush();
Why is this happening?
See Question&Answers more detail:os