Laravel Carbon subtract days from current date

后端 未结 3 1676
抹茶落季
抹茶落季 2021-02-01 11:43

I am trying to extract objects from Model \"Users\" whose created_at date has been more than 30 days from today.

Carbon::now() ==> I want a

3条回答
  •  天涯浪人
    2021-02-01 12:18

    From Laravel 5.6 you can use whereDate:

    $users = Users::where('status_id', 'active')
           ->whereDate( 'created_at', '>', now()->subDays(30))
           ->get();
    

    You also have whereMonth / whereDay / whereYear / whereTime

提交回复
热议问题