doushou1298 2016-08-16 07:47
浏览 122
已采纳

whereBetween在eloquent查询之间返回空输出

I'm trying to use 'whereBetween' eloqouent query with two given start and end dates.

$first_day_this_month = date('Y-m-01 H:s:i'); //get the first day of the current month
$yesterDay = date('Y-m-d H:s:i',strtotime("-1 days")); //get yesterday's date

$d = m_chat_history::where('employee_id',$request->other_id)
                ->whereNull('to_group')->where('to_employee_id',$request->id)
                ->whereBetween('created_at',[$yesterDay,$first_day_this_month])
                ->get();

I make sure I have all the required data for the query by 'var_dump' and it did gives me all the required data needed for the query but the query returns me an empty output. Any ideas, clues, suggestions, help, recommendations please? I tried to remove the 'whereBetween' and my query works like it returns me the expected output but with 'whereBetween', the return output is empty.

  • 写回答

2条回答 默认 最新

  • doushang4293 2016-08-16 07:55
    关注

    Make sure to use the same type and format as created_at when defining the values for whereBetween. As you're using datetime you could define edge values like (just one of many ways of doing it):

    $first_day_this_month = date('Y-m-01 H:i:s');
    $yesterday = date('Y-m-d H:i:s', strtotime("-1 day"));
    

    Also make sure of the order of params (still please consider edge cases like first day of the month where $yesterday would be smaller, so you have to add some logic and be careful):

    ->whereBetween('created_at', [$first_day_this_month, $yesterday])
    

    Edit: wasn't timestamp...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错