Php 拉威尔:获取所有过去过期的记录?
我有一个变量,我从GameMute模式中获取记录,我需要知道如何才能只获取expires\u at尚未过期的记录。它的格式就像在Php 拉威尔:获取所有过去过期的记录?,php,laravel,Php,Laravel,我有一个变量,我从GameMute模式中获取记录,我需要知道如何才能只获取expires\u at尚未过期的记录。它的格式就像在 $mutes = GameMute::orderBy('created_at', 'asc')->get(); 谷歌上到处都是,但都是格式化时间之类的东西 谢谢。试试哪里的条件 $mutes = GameMute::whereRaw('expires_at > now()')->orderBy('created_at', 'asc')->ge
$mutes = GameMute::orderBy('created_at', 'asc')->get();
谷歌上到处都是,但都是格式化时间之类的东西
谢谢。试试哪里的条件
$mutes = GameMute::whereRaw('expires_at > now()')->orderBy('created_at', 'asc')->get();
像这样使用碳
$mutes = GameMute::where('expires_at','>', \Carbon\Carbon::now())
->orderBy('created_at', 'asc')->get();
试试这些
$mutes = GameMute::where('expires_at ', '>', new DateTime('today'))->orderBy('created_at', 'asc')->get();
希望您的expire_at列是日期类型的列
$mutes = GameMute::where('expires_at','>',date('Y-m-d'))
->orderBy('created_at', 'asc')
->get();
或者,如果它包含日期时间值,如“2017-07-31 16:50”,则您可以这样查询:
$mutes = GameMute::whereDate('expires_at','>',date('Y-m-d'))
->orderBy('created_at', 'asc')
->get();
试试这个:
$date = date("Y-m-d h:i:s");
$users = DB::table('users')->whereDate('expires_at',">",$date))
->orderBy('created_at', 'asc')->get();
以上两个查询之间的区别是什么如果列只包含日期,则不需要使用whereDate,但如果它包含日期时间值,如“2017-07-31 16:50”,则可以这样查询。它将只检查日期部分