Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

i have a problem setting a datetime attribute to the current date , if i force it to current timestamp i get a " Call to a member function format() on string" 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;


}
like image 392
petrucci Avatar asked Nov 27 '16 04:11

petrucci


1 Answers

You could return a \DateTime object as example:

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

Hope this help

like image 193
Matteo Avatar answered Sep 20 '22 12:09

Matteo