Invalid datetime format: 1292 Incorrect date value: '2017-June-30' Dear all
I have one problem with Invalid datetime format: 1292 Incorrect date value: '2017-June-30'
when I try to save new record.
Here is my Model formated
protected $dateFormat = 'Y-M-d H:i:s';
Here is my JQuery datepicker formated
dateFormat: "yy-MM-dd",
Please help.
2017-Juni-30 is not a valid date format for your model.
You have two options here. Either let your backend parse the posted format and convert it to the correct format (Carbon for example). Another solution would be using the altFormat option in the datepicker and send that value to the server.
See: https://api.jqueryui.com/datepicker/#option-altFormat
@bobbybouwmann , actually I already set it in my model but it still not correct, here is my code
public function setCloseDate($close_date)
{
$this->attributes['close_date']=Carbon::createFromFormat('Y-M-d H:i:s',$close_date);
}
What is not correct? Did you check the value you get in the method?
Also if you want to set a model attribute you need the following structure
public function set{Field}Attribute($value)
{
$this->attributes['field'] => $value;
}
So in your case that should be setCloseDateAttribute($value)
@bobbybouwmann , here is what i got
Invalid datetime format: 1292 Incorrect date value: '2017-June-30' for column 'closing_date'
Like I said, it's not a valid database format for PHP or Carbon. I tried it myself, but it's not possible. You either need to parse the date by hand or post a different date like I mentioned with the altFormat option in jQuery
@bobbybouwmann , now it worked, but I got another problem, here is my code :
$jobs->email_new_application=1;
$jobs->company_id=1;
$jobs->province_id=18;
$jobs->categories()->attach($request['job_occupation']);
$jobs->contractType()->save($request['job_contact_type']);
$jobs->save();
Error Message that I got
insert into `job_job_category` (`job_category_id`, `job_id`) values (?, ?), (?, ?)', array('1', null, '14', null)
And the question is how can I execute this query ?
Please sign in or create an account to participate in this conversation.