David McGregor
David McGregor

Reputation: 132

A four digit year could not be found Data missing in Carbon

InvalidArgumentException: A four digit year could not be found
Data missing in carbon/src/Carbon/Carbon.php:425

Getting this error in my apache logs. What is the cause of this type of error?

Upvotes: 3

Views: 7853

Answers (2)

Yasir Ijaz
Yasir Ijaz

Reputation: 1064

I faced and fixed that problem and problem was that I was using the guard method in the eloquent model and then I was trying to save data using create method. Problem was that the array I was providing to create method as a parameter has an extra column apart from the table's column so somehow our created_at or updated_at field was getting disturbed. Once I fixed the extra column issue. The error was removed.

Upvotes: 0

David McGregor
David McGregor

Reputation: 132

Running this on the date first should fix it. Likely getting an invalid date from the front-end.

function validateDate($date, $format = 'Y-m-d H:i:s'){
    $d = DateTime::createFromFormat($format, $date);
    return $d && $d->format($format) == $date;
}

function was copied from this answer or php.net

Upvotes: 2

Related Questions