Welcome Guest, Not a member yet? Register   Sign In
Best practice for date in entity
#1

hello

in a form i have a date in format 'dd/mm/yyyy'

i use entity and i want save the date in sql with model

i do in my model
Code:
$myEntity = new TheEntity($data);
        if ($this->save($myEntity))

this send me an error

DateTime::__construct(): Failed to parse time string (19/03/2016) at position 0 (1): Unexpected character


i have create a setter in my entity
Code:
protected $dates = ['date_naissance'];
   
    public function setDateNaissance($date)
    {
        if (empty($date)) {
            $this->attributes['date_naissance'] = null;
            return $this;
        }else{
            $this->attributes['date_naissance'] = date('Y-m-d', strtotime(str_replace('/', '-', $date)));
            return $this;
        }
    }
but the setter isn't call before the error
Reply


Messages In This Thread
Best practice for date in entity - by paul - 10-12-2020, 11:59 AM
RE: Best practice for date in entity - by tmtuan - 10-12-2020, 07:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB