Quantcast
Channel: How To Add Interval 30 Days in Laravel (MYSQL) - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Rwd for How To Add Interval 30 Days in Laravel (MYSQL)

$
0
0

The reason you're not getting the results you want is because you're using where instead of whereRaw. In this case your query going to return:

select * from `projects` where end_date BETWEEN     CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 30 DAY) is null

(notice the is null part).

To get the results you want change where to whereRaw (you can remove the DB::raw):

project::whereRaw('end_date BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 30 DAY)')->get();

Alternatively, you could use a mixture of whereBetween and Carbon:

project::whereBetween('end_date', [now(), now()->addDays(30)])->get();

Check out this answer for more information.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>