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

octoxan's avatar

How to seed a date field?

Trying to seed some data for some settings for an application, and some of the settings have a date column, in the standard 2000-01-01 format.

How does one go about seeding this?

Setting::create([
    'name' => 'Start Date',
    'date' => '1900-01-01'
]);

I don't want a random date, I want it set to a specific date.

Throws the error: [InvalidArgumentException] The separation symbol could not be found Unexpected data found. Trailing data

0 likes
6 replies
octoxan's avatar

@TerrePorter

This didn't fix the issue, sadly.

I now have this in my Setting model.

protected $dates   = [
    'created_at',
    'updated_at',
    'date'
];

But running the seed still throws the same error

"[InvalidArgumentException] The separation symbol could not be found Unexpected data found. Trailing data"

Stops throwing the error if I remove this seeder.

octoxan's avatar

If I try removing the quotes around the date, so that it looks like this...

Setting::create([
    'name' => 'Start Date',
    'date' => 1900-01-01
]);

The error becomes:

"[InvalidArgumentException] The separation symbol could not be found. Data missing"

octoxan's avatar
octoxan
OP
Best Answer
Level 3

I did at one point try adding this to the top of the DatabaseSeeder.php file:

use Carbon\Carbon;

and then using...

Setting::create([
    'name' => 'Start Date',
    'date' => Carbon::create('2000', '01', '01')
]);

but received the same error.

What ended up working was changing it from Setting::create to..

DB::table('settings')->insert([
    'name' => 'Start Date',
    'date' => Carbon::create('2000', '01', '01')
]);
3 likes

Please or to participate in this conversation.