Laravel 获取日期差异

Laravel get date difference

我有以下

"end_time" represents datetime in unix format

$vouchers = DB::table('deals_sales')
                ->whereIn('status', [0, 1])
                ->where('end_time', '>=', strtotime("+5 day"))
                ->get();

我想要实现的是获得从现在到接下来 5 天之间将要结束的所有结果,但通过我的查询,我什至可以得到那些将在 10 天后过期的结果。

我只是不明白如何获得它的逻辑。

有什么想法吗?

谢谢

由于您使用的是整数时间戳,因此您可能正在寻找 whereBetween。尝试以下操作:

$vouchers = DB::table('deals_sales')
                ->whereIn('status', [0, 1])
                ->whereBetween('end_time', [time(), strtotime("+5 day")])
                ->get();

这将为您提供从现在到未来 5 天 end_time 的条目。