Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 2 characters in body
Source Link
BMBM
  • 16.1k
  • 19
  • 83
  • 135

You map your entityproperty as DateTime type then set the value in the constructor using a new DateTime instance:

/** * @Entity * @Table(name="...") */ class MyEntity { /** @Column(type="datetime") */ protected $registration_date; public function __construct() { $this->registration_date = new DateTime(); } } 

This works as the constructor of a persisted class is not called upon hydration.

You map your entity as DateTime type then set the value in the constructor using a new DateTime instance:

/** * @Entity * @Table(name="...") */ class MyEntity { /** @Column(type="datetime") */ protected $registration_date; public function __construct() { $this->registration_date = new DateTime(); } } 

This works as the constructor of a persisted class is not called upon hydration.

You map your property as DateTime type then set the value in the constructor using a new DateTime instance:

/** * @Entity * @Table(name="...") */ class MyEntity { /** @Column(type="datetime") */ protected $registration_date; public function __construct() { $this->registration_date = new DateTime(); } } 

This works as the constructor of a persisted class is not called upon hydration.

Source Link
BMBM
  • 16.1k
  • 19
  • 83
  • 135

You map your entity as DateTime type then set the value in the constructor using a new DateTime instance:

/** * @Entity * @Table(name="...") */ class MyEntity { /** @Column(type="datetime") */ protected $registration_date; public function __construct() { $this->registration_date = new DateTime(); } } 

This works as the constructor of a persisted class is not called upon hydration.