如何在上周展示文章?
PHP代码
$articles= Article::where('created_at', ">", ? )->take(100)->get();
如何显示上周的文章从现在开始?
答案 0 :(得分:2)
您可以使用whereBetween()
和Carbon获取上周的数据:
$start = Carbon::now()->subWeek()->startOfWeek();
$end = Carbon::now()->subWeek()->endOfWeek();
Article::whereBetween('created_at', [$start, $end])->take(100)->get();
答案 1 :(得分:1)
试试这个
$articles= Article::where('created_at', ">=",
DB::raw("curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY"))->take(100)->get();
答案 2 :(得分:1)
使用DB::raw()
$articles= Article::where('created_at', ">", DB::raw('NOW() - INTERVAL 1 WEEK'))->take(100)->get();
我假设last week from now
表示从现在起的最后7天
答案 3 :(得分:0)
我试试这个,它对我有用!
$articles= Article::where('created_at', ">", date("Y-m-d HH:ii", time() - 10080 * 60))->take(100)->get();