Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

t0berius's avatar

cannot insert date into database

When I try to update some records in my database I try to set their birthdate to the "birth_date" field. Now I get this error all the time for every entry user tries to make:

Incorrect datetime value: '1963-04-20 00:00:00' for column 'birth_date' at row 1 (SQL: update `logs` set `birth_date` = 1962-03-19 00:00:00 where `id` = 238)

I created the "birth_date" field using this migration:

$table->timestamp('birth_date')->nullable();

My model has this timestamp fields:

public $dates = [
        'created_at', 'updated_at', 'birth_date', 'deleted_at',
];

Any idea where things go wrong?

0 likes
6 replies
Snapey's avatar

You need to change the column type to a date since;

The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

You cannot store 1963 in a timestamp

5 likes
willvincent's avatar

Not to mention there's not much point in storing a birthdate without a time anyway.. ;)

1 like
willvincent's avatar

@jaheller right, which is another reason date is more appropriate than timestamp, aside from the available range of values for timestamp fields not supporting the date you're trying to insert. That's all I was saying. :)

Please or to participate in this conversation.