Reputation: 75
I'm calling data from a table from database. I'm adding WHERE statement to filter data that are registered from today until 14days ago. Below are example of my code:
$data=DB::connection('oracle_mybase')->table('my_dndomain')
->where('my_dndomain.domain_status','=',86)
->where('my_dndomain.domain_reg_date','>=',DB::raw('to_date(sysdate)-14'))
->where('my_dndomain.domain_extension','=','.com.my')
->orwhere('my_dndomain.domain_extension','=','.org.my')
->orwhere('my_dndomain.domain_extension','=','.net.my')
->orwhere('my_dndomain.domain_extension','=','.my')
->get();
But i couldn't get the data.
Upvotes: 1
Views: 137
Reputation: 11594
you can use ->whereBetween('my_dndomain.domain_reg_date',array($now->subDays(14), $now))
$now = Carbon\Carbon::now();
$twoweeksago = Carbon\Carbon::now()->subDay(14);
$data=DB::connection('oracle_mybase')->table('my_dndomain')
->where('my_dndomain.domain_status','=',86)
->whereBetween('my_dndomain.domain_reg_date',array($twoweeksago, $now))
->where('my_dndomain.domain_extension','=','.com.my')
->orwhere('my_dndomain.domain_extension','=','.org.my')
->orwhere('my_dndomain.domain_extension','=','.net.my')
->orwhere('my_dndomain.domain_extension','=','.my')
->whereDate('field_name', '<', $now)
->get();
Upvotes: 2
Reputation: 1925
You can use whereBetween
whereBetween('date', array(Carbon::now()->subWeeks(2), Carbon::now()))
Upvotes: 3