In my Symofny project I want for my entity to have timestamp
field.
JavaScript
x
/**
* @ORMColumn(type="datetime", nullable=false)
*/
private $timestamp;
/**
* @ORMPreUpdate
* @throws Exception
*/
public function setTimestamp()
{
$this->timestamp = new DateTime("now");
return $this;
}
I want to be saved in timestamp format? How can I accomplish that? Like // => 1387909800
I am on Symfony 4.3 version.
Advertisement
Answer
Try getTimestamp();
JavaScript
/**
* @ORMColumn(type="datetime", nullable=false)
*/
private $timestamp;
/**
* @ORMPreUpdate
* @throws Exception
*/
public function setTimestamp()
{
$date = new DateTime();
$this->timestamp = $date->getTimestamp();
return $this;
}