Reputation: 2945
I've got two tables in my SQL database. Both have a period_from
column as the common date format. Both tables have data back dating for several weeks, I've joined my tables, and am selecting the appropriate columns that I need.
Everything works great and gives me the correct data, but as soon as I add whereDate()
I get nothing, an empty array. I've tried the bogstandard where()
and have also tried targetting my table followed by my column, e.g: *.period_from
, not sure why it's not giving me any results here.
$from = Carbon::now()->subDays(14);
$to = Carbon::now();
$order = 'asc';
$data = DB::table('data_source_one as DGA')
->join('data_source_two as DLCA', 'DGA.created_at', '=', 'DLCA.created_at')
->where('event_action', 'Step 1 Loaded: (Loan Details)')
->select('event_count', 'sessions', 'leads', 'DGA.created_at', 'DGA.period_from', 'DGA.period_to')
->whereDate('DGA.period_from', '>=', $from)
->whereDate('DGA.period_to', '<=', $to)
->orderBy('DGA.created_at', $order)
->get();
Upvotes: 0
Views: 540
Reputation: 4412
you can just do this :
$from = Carbon::now()->subDays(14);
$to = Carbon::now();
$order = 'asc';
$data = DB::table('data_source_one as DGA')
->join('data_source_two as DLCA', 'DGA.created_at', '=', 'DLCA.created_at')
->where('event_action', 'Step 1 Loaded: (Loan Details)')
->select('event_count', 'sessions', 'leads', 'DGA.created_at', 'DGA.period_from', 'DGA.period_to')
->where('DGA.period_from', '>=', $from)
->where('DGA.period_to', '<=', $to)
->orderBy('DGA.created_at', $order)
->get();
Upvotes: 1