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

RahulHuilgol's avatar

Changing from date to datetime

I have a date column defined in my model called 'datevalue'. $table->date('datevalue');

I need to change this now to type datetime. How should I write this in the migration file? Please help me out from your experience. Thanks, everyone!

0 likes
5 replies
janosk's avatar
janosk
Best Answer
Level 23

Something like this:

Schema::table('yourtablename', function (Blueprint $table) {
    $table->dateTime('datevalue')->change();
});

Alternatives: https://laravel.com/docs/6.x/migrations#modifying-columns

Note: Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column:

composer require doctrine/dbal
RahulHuilgol's avatar

Thanks for the response, Janosk! Valuable advice about dbal. Thank you.

1 like
Snapey's avatar

Please mark it resolved so that others don't keep looking at it.

Please or to participate in this conversation.