A two digit month could not be found Data missing in Laravel

时光毁灭记忆、已成空白 提交于 2019-12-12 11:18:00

问题


I'm having a table where I'm storing the data in date format through datepicker. While storing the date I'm doing something like this:

$data['schedule'] = Carbon::parse($request->schedule)->toDateTimeString();

then in model I've defined like following:

protected $dates = [
    'schedule', 'created_at', 'updated_at', 'deleted_at'
];

Now while retrieving the date I'm using diffForHumans() something like this:

$event->schedule = $event->schedule->diffForHumans();

But it is throwing an error like this:

A two digit month could not be found. Data missing

I checked mySQL database for the format , I'm having dates like this:

2017-07-02 14:38:23

Edit:

Previously I was having an issue while storing the date in tables, please refer to How to format date receiving through Vuejs Datepicker in laravel for the detailed description. It throws error of:

Invalid datetime format: 1292 Incorrect datetime value: '2017-05-04T18:30:00.000Z' for column 'schedule' at row 1

So I chose to use Carbon::parse while storing it in database.

How to resolve this, help me out.

Thanks.


回答1:


Try with an accessor method in your model.

public function getScheduleAttribute($value)
{
    return Carbon::parse($value)->diffForHumans();
}

and access the attribute as

$event->schedule;



回答2:


Try to set datetime format ('Y-m-d H:i:s')

and run



来源:https://stackoverflow.com/questions/44880705/a-two-digit-month-could-not-be-found-data-missing-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!