Could not find a two-digit month. No data in Laravel

I have a table where I store data in date format via datepicker. When saving the date, I do something like this:

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

then in the model that I defined as follows:

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

Now, getting the date, I'm using diffForHumans() something like this:

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

But he gives the following error:

Could not find a two-digit month. Missing data

I checked the mySQL database for the format, I have dates like this:

 2017-07-02 14:38:23 

Edit:

I used to have a problem while storing dates in tables, see How to format date retrieval via Vuejs Datepicker in laravel for a detailed description. It gives an error:

Invalid date and time format: 1292 Invalid date and time value: '2017-05-04T18: 30: 00.000Z' for the column schedule in row 1

So I decided to use Carbon::parse , storing it in the database.

How to solve this problem, help me.

Thanks.

+3
source share
2 answers

Try using the access method in your model.

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

and access the attribute as

 $event->schedule; 
+2
source

Try setting the date and time format ('Ymd H: i: s')

and run

+2
source

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


All Articles