laravel date and time column concat to datetime column
A migration could be used to do this:
You can create one using php artisan make:migration MergeDateColumns
and then do:
class MergeDateColumns extends Migration {
public function up() {
Schema::table('your table name', function (Blueprint $table) {
$table->dateTime('publish_date_time');
});
DB::table('your table name')
->update([ 'publish_date_time' => DB::raw("CONCAT(publish_date,' ', publish_time)") ]);
Schema::table('your table name', function (Blueprint $table) {
$table->dropColumn('publish_date');
$table->dropColumn('publish_time');
});
}
public function down() {
Schema::table('your table name', function (Blueprint $table) {
$table->date('publish_date');
$table->time('publish_time');
});
DB::table('your table name')
->update([
'publish_date' => DB::raw("DATE(publish_date_time)"),
'publish_time' => DB::raw("TIME(publish_date_time)")
]);
Schema::table('your table name', function (Blueprint $table) {
$table->dropColumn('publish_date_time');
$table->dropColumn('publish_time');
});
}
}
This merges the columns when you migrate and will split them again when you roll back.
To be safe I would take a backup of the data before running this on production but I don't think it would cause problems.