Laravel 5搜索记录今天30分钟或更旧 [英] Laravel 5 search records 30min and older for today

查看:118
本文介绍了Laravel 5搜索记录今天30分钟或更旧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取所有30分钟以前的记录,今天这些记录的字段称为smsed value =到0.

I am trying to get all records that are 30min old and are today with a field called smsed value = to 0.

我要执行的操作是获取数据库中具有今天日期且早于30分钟的所有记录.

What i am trying to do is get all the records in my database with todays date and are older than 30min.

$data = DB::table('applicant')->whereRaw('AppDate < (NOW() - INTERVAL 30 MINUTE)')->where('smsed','=',0)->limit(5000)->get();

上述操作是获取数据库中的所有记录,而不仅仅是今天.

what the above does is get all records in the DB and not only for today.

推荐答案

这是因为您只要求它提供30分钟以上的记录,并且不包含任何将其限制在今天的记录.

This is because you only asking it for records that are over 30minutes old and not including anything to limit it to today.

您可以使用类似whereBetween的内容:

You could use something like whereBetween:

$data = DB::table('applicant')
    ->whereBetween('AppDate', [Carbon\Carbon::now()->startOfDay(), Carbon\Carbon::now()->subMinute(30)])
    ->where('smsed', '=', 0)
    ->limit(5000)
    ->get();

或者,如果您只想保留sql函数,则可以执行以下操作:

Alternatively, if you just want to keep your sql functions you could do something like:

$data = DB::table('applicant')
    ->whereRaw('AppDate < (NOW() - INTERVAL 30 MINUTE)')
    ->whereRaw('DATE(AppDate) = CURDATE()')
    ->where('smsed','=',0)
    ->limit(5000)
    ->get();

希望这会有所帮助!

这篇关于Laravel 5搜索记录今天30分钟或更旧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆