0

I'm trying to retrieved records base on its 'created_at' timestamp column, where yesterday is the start date and retrieved records until to the start of the current month

 $h_msg1 = m_chat_history::where('employee_id',$request->other_id)->whereNull('to_group')->where('to_employee_id',$request->id)->whereBetween('created_at', [
            Carbon::parse('yesterday')->startOfDay(),
            Carbon::now()->endOfMonth(),
        ])->get();

But unfortunately it throws me and empty result, any help, ideas, clues, suggestions, recommendations please?

Juliver Galleto
  • 8,831
  • 27
  • 86
  • 164
  • You say start of month, but your code seem to suggest end of month – Epodax May 26 '16 at 07:16
  • When you get results, even zero results, obviously there are no rows matching your query. Try and retrieve the raw executed query and check if there is something wrong. You can output the raw query by using toSql() [link](http://stackoverflow.com/questions/18236294/how-do-i-get-the-query-builder-to-output-its-raw-sql-query-as-a-string) Or you can use the laravel debug bar with much more info [link](https://github.com/barryvdh/laravel-debugbar). – Thomas Van der Veen May 26 '16 at 07:17

2 Answers2

0

try below code

    $first_day_this_month = date('Y-m-01 H:s:i');
    $yesterDay = date('Y-m-d H:s:i',strtotime("-1 days"));
    $record = m_chat_history::whereBetween('created_at',[$first_day_this_month, $yesterDay])->get();
DsRaj
  • 2,288
  • 1
  • 16
  • 26
0

Yo need to use startOfMonth according to your message:

$h_msg1 = m_chat_history::where('employee_id',$request->other_id)->whereNull('to_group')->where('to_employee_id',$request->id)->whereBetween('created_at', [
                Carbon::parse('yesterday')->startOfDay(),
                Carbon::now()->startOfMonth()
            ])->get();
AlSan
  • 383
  • 5
  • 9