简体   繁体   中英

get records from database base on the specified date range laravel 5

How can I retrieved records from the database using carbon dates with the specified date range eg retrieved records from "2014-10-13" to "2015-11-18"? any ideas, help, suggestions, clues, recommendations please?

You can use the whereBetween method. So, just as an example, lets say you have two Carbon dates.

$earlier = Carbon::yesterday();
$later = Carbon::today();

Model::whereBetween('column', [$earlier, $later])->get();

The first parameter represents the column you are checking. The second parameter is an array of the two dates.

Using the dates in your question, you can generate the carbon dates like this:

$earlier = Carbon::parse('2015-09-11');
$later = Carbon::parse('2015-09-14');

Model::whereBetween('column', [$earlier, $later])->get();

The parse method is pretty awesome.

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