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

Rangana's avatar

what is data type to store date in laravel?

simply I need store date like 02 Jul 2019 in my laravel app. how can I give data type in my migration file to store like above date?

0 likes
5 replies
Snapey's avatar

use date column

it will be stored in your database's Date format.

You then pull it from the database and convert it into whatever format you need for presentation. Use Carbon for this.

Rangana's avatar

@snapey I have date like '02 jul 2019' in My data input. then may I use date type to store like above date value?

Snapey's avatar

You can use Carbon\Carbon::parse($date); and then pass the Carbon object to eloquent model.

eg

$model = Model::create([
    'stuff' => $request->stuff,
    'myDate' => Carbon\Carbon::parse($request->myDate)
]);
jlrdw's avatar

I have date like '02 jul 2019' in My data input.

Study and learn data types and how and what happens with them.

That's what "carbon", "php date format" etc is for, to perhaps display a certain way.

But no matter the display for user

It is stored in the database as YYYY-MM-DD for MySql.

Other DB's may differ. Start here:

https://dev.mysql.com/doc/refman/8.0/en/data-types.html

And a timestamp is different from date, learn the difference now, prior to having thousands records entered wrong.

LA87's avatar

Don't store as date if you have different timezone that UTC.

Please or to participate in this conversation.