我想检查今天的日期是否介于 dat 存储在 数据库。现在我用 laravel eloquent 来做这件事:
return Set::where('type', $type)
->where('active_from', '<=', date("Y-m-d"))
->where('active_until', '>=', date("Y-m-d"))
->first();
这是正确的吗?
最佳答案
假设 active_from
和 active_until
仅包含日期是正确的,但如果它们包含带时间的日期,您可能应该使用 whereDate
而不是 where
像这样:
return Set::where('type', $type)
->whereDate('active_from', '<=', date("Y-m-d"))
->whereDate('active_until', '>=', date("Y-m-d"))
->first();
此外,查看代码我很确定您应该以另一种方式使用运算符:active_from
应该是 >=
和 active_until
应该是 <=
关于php - Laravel 检查日期是否在两个日期之间。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47212695/