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

Santosh_Mohapatra's avatar

Set date format

Hi, I have defined a migration in which I have a date field i.e, dob. How to set the date format for it?

Example: public function up() { Schema::create('contacts', function (Blueprint $table) { $table->increments('contactid'); $table->string('name', 75)->nullable(); $table->string('email', 100)->nullable(); $table->timestamp('dob')->nullable(); $table->timestamps(); }); }

Thanks Santosh

0 likes
6 replies
Santosh_Mohapatra's avatar

Thanks, that is fine. But I was thinking of directly setting the date format in migration.

mahekarim's avatar

You can add $table->timestamp("whatIsTime"); in migration file and add this code to your model

protected $casts = [ 'whatIsTime' => 'date:hh:mm' ];

jlrdw's avatar

$table->timestamp('dob') Don't use timestamp for DOB.

Edit: You got me, old post.

Please or to participate in this conversation.