获取每行中两个日期之间的差异

Get the difference between two dates in every rows

我需要获取 2 个日期之间的差异,而不仅仅是 2 个特定日期之间的差异,我正在谈论具有 "pdt_expires" 列的 table,我想显示多少天直到这个日期,但在每一行。例如:

我只看到了 2 个特定日期的上千个解决方案,但 none 对于这个案例。我想知道我需要:

或 - 视图中的一个函数,它获取 $product->pdt_expire 并获取最终值

所以任何帮助都会很棒,谢谢。

如何使用简单的 DATEDIFF 查询实现它:

ProductModel::select([
    'products.*',
    \DB::raw('DATEDIFF(pdt_expires, NOW()) as expires_in')
])->get();

因此,在您拥有的每个产品中,它都会有一个名为 expires_in 的附加列,用于存储 NOWpdt_expires 之间的不同天数。

日期差异:How to get the number of days of difference between two dates on mysql?