![](/img/trans.png)
[英]Select record(s) from mysql table where date is greater than or equal to today
[英]Laravel get record with date greater than today
我有一个表,上面有一些带日期的事件,这个表有列from_date
to_date
。 我只想从数据库中选择属于该差距的那些记录。 但是,我什至无法选择to_date
大于today
那些。
这就是我正在尝试的
$date = today()->format('Y-m-d')
Action::where('to_date', '<=', $date)->get()
这就是我得到的
=> Illuminate\Database\Eloquent\Collection {#3211
all: [
App\Action {#3217
id: 9,
name: "Знижка 10%",
from_date: "2018-09-19",
to_date: "2018-09-21",
image_path: "actions/September2018/8AUigc8LFZnqyANy7k7J.jpg",
created_at: "2018-09-25 16:50:00",
updated_at: "2018-09-25 16:50:57",
infinite: 0,
},
App\Action {#3201
id: 10,
name: "Не должно бить відно",
from_date: "2016-09-14",
to_date: "2016-09-22",
image_path: "actions/September2018/8QVS0uPI4S48kWg3ltza.jpg",
created_at: "2018-09-25 17:32:08",
updated_at: "2018-09-25 17:32:08",
infinite: 0,
},
],
}
由于某种原因,2016 年过去了
您错过了查询条件。 做这个:
$date = today()->format('Y-m-d')
Action::where('to_date', '>=', $date)->get()
在我的情况下,这是有效的:
Action::whereDate('to_date', '>', Carbon::now())->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.