How to get last 7 days records from table using Mysql Query?

Today now in this post i will show you How to get last 2 days records from table using Mysql Query? sometimes We may need to get the few days ago records from table as like last 2 days, last 7 days, last 15days or last 30 days etc. Most of the developer choose the other logic but we can easily get this by using mysql query(by using CURDATE and INTERVAL).

So now in this example mysql query i have only one table as “elements” and the columns are id, title, description, created_at(timestamps) and update_at. Now we need to get all records of last 7 we can fetch all fields value by using CURDATE and INTERVAL of mysql.

Now In the following example we can see how to select data of last 7 days.


SELECT * FROM `elements`
WHERE created_at >= ( CURDATE() - INTERVAL 7 DAY )

Read Also: How to convert file extension using CloudConvert in laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →