Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel: DATE_ADD in where clause

I want to subtract days from the db column and then compare it with the current date using DATE_ADD function. Is this possible?

 $valid_status_query->whereRaw('DATE_ADD("d",-3, "date_to")', '<=', Carbon::now()->format('Y-m-d'));

For example, if the column date is 2022-07-20 then it should use 2022-07-17 to compare in where clause at the end.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use it like this:

$valid_status_query->whereRaw("DATE_SUB(date_to, INTERVAL 3 DAY) <= ?", [Carbon::now()->toDateString()]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading