I don\'t know which is the best way to store a timestamp in the database. I want to store the entire date with hours minutes and seconds but it only stores the date ( for in
Building on @Pratt's answer I did this. I have 2 fields in my entities one for created and one for modified.
/**
* @ORM\Column(type="datetime")
*/
protected $created_at;
/**
* @ORM\Column(type="datetime")
*/
protected $modified_at;
And then using annotation I call this on prePersist and preUpdate
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updatedTimestamps()
{
$this->setModifiedAt(new \DateTime(date('Y-m-d H:i:s')));
if($this->getCreatedAt() == null)
{
$this->setCreatedAt(new \DateTime(date('Y-m-d H:i:s')));
}
}
The function could be broken up into 2 functions one for create one for update, but this is working so I see no reason for the extra code when this is working properly.