[英](Laravel) check if today is between two dates based on a starting date
[英]Laravel check if date is between 2 dates.
我想检查今天的日期是否存在于数据库中的日期之间。 现在我用laravel雄辩的方式做到这一点:
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
应该是<=
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.