我们要计算数据库中两个不同日期字段之间的持续时间。谁能帮助将此SQL查询转换为Laravel中的数据库迁移?
CREATE TABLE api_incident_duration
(START DATETIME, END DATETIME, elapsed DECIMAL(5, 2)
AS (ROUND(TIMESTAMPDIFF(MINUTE, START, END) / 60, 2)));
也许:
$table->dateTime('startdatetimepicker')->nullable();
$table->dateTime('enddatetimepicker')->nullable();
$table->decimal('elapsed', 5, 2)
->virtualAs(ROUND(TIMESTAMPDIFF(MINUTE, startdatetimepicker, enddatetimepicker) / 60, 2));