dou7851 2017-06-01 06:34
浏览 141
已采纳

Laravel - 使用eloquent选择开始日期和结束日期之间的行

I want to convert this query into laravel eloquent,

select * from schedule where (now() between start_date and end_date);

I tried using whereBetween, but I got some error.

$schedule = Schedule::whereBetween(Carbon::now(), ['start_date', 'end_date'])->get();

the error looks like this

QueryException in Connection.php line 647: SQLSTATE[42S22]: Column not found: 1054 Unknown column '2017-06-01 06:17:30' in 'where clause' (SQL: select * from schedule where 2017-06-01 06:17:30 between start_date and end_date)

any idea?

  • 写回答

5条回答 默认 最新

  • doucongmishang2385 2019-04-29 07:38
    关注
    $from = $request->from;
    $to = $request->to;
    $title="Sales From: ".$from." To: ".$to;
    $sales = Sale::whereBetween('created_at', [$from.' 00:00:00',$to.' 23:59:59'])->get();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?