How to set date attribute to current date in php using symfony 3

I have a problem with setting the datetime attribute to the current date, if I force its current timestamp, I get "Call to the member function () format in the line" ERROR

**here are my getter and setter with some modifications**
public function getDateajout()
{
    date_default_timezone_set('Africa/Tunis');
    $dateajout=date_default_timezone_get();
    return $this->dateajout;
}

public function setDateajout($dateajout)
{

    $this->dateajout =$dateajout;


}
+4
source share
1 answer

You can return the \ DateTime object as an example:

/**
 *
 * @return \DateTime
 */    
public function getDateajout()
{
    return new \DateTime('now', (new \DateTimeZone('Africa/Tunis'));
}

Hope for this help

+4
source

Source: https://habr.com/ru/post/1662050/


All Articles