Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle MySQl null dates returning '-0001-11-30 00:00:00'

When my MySQl dates are null, PHP returns them as '-0001-11-30 00:00:00'.

I know this is because I am using Europe timezone but how can I handle this?

I keep getting:

InvalidArgumentException in Carbon.php line 425:
Unexpected data found.
in Carbon.php line 425
at Carbon::createFromFormat('Y-m-d H:i:s', '-0001-11-30 00:00:00') in Model.php line 2915

How can I fix this?

Mick

NB: This is different from : How do you explain the result for a new \DateTime('0000-00-00 00:00:00')?

It is different because I am asking what I am supposed to do about it.

like image 492
Mick Avatar asked Mar 24 '16 10:03

Mick


1 Answers

Basing on this great answer: https://stackoverflow.com/a/19075291/4499267 at point 8) it says that

MySQL stores "0000-00-00 00:00:00" if you set a datetime column as NULL, unless you specifically set the column to allow null when you create it.

So that might be the solution, to create the table with a nullable datetime column

like image 137
Phate01 Avatar answered Oct 22 '22 03:10

Phate01