简体   繁体   中英

How can i get data from today's date and before?

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.

您可以使用whereBetween

whereBetween('date', array(Carbon::now()->subWeeks(2), Carbon::now()))

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM