How to Get Last 2 Days Records from Table using MySQL Query?
We may sometimes require to get few days ago records from table like last 2 days, last 3 days, last 10 days or last 15 days etc. Most of developer choose other logic but we can easily get using mysql query(using CURDATE and INTERVAL).
In this example mysql query i have one table "elements" and columns are id, title, description, created_at(timestamps) and update_at, Now we will get all records of last 2 days.so you can fetch fields value using CURDATE and INTERVAL of mysql. In following example you can see how to select data of last two days.
SELECT * FROM `elements`
WHERE created_at >= ( CURDATE() - INTERVAL 2 DAY )
I hope it can help you...
We are Recommending you
- How to Get Last Record in Codeigniter?
- MySQL Query to Get Current Year Data Example
- Trigger on After Delete with Update Query MySQL Example
- MySQL Query to Get Current Month Data Example
- MySQL Query to Remove Numbers from String in a Column Example
- MySQL Query to Remove Special Characters from String
- How to Add MySQL Trigger from Migration in Laravel?
- How to Import CSV File using MySQL?
- How to fetch this week records in MySql ?
- Laravel Change Date Format using Carbon Example
- How to Check Empty or Null Data using MySQL Query?
- How to Copy One Table Data into Another Table using MySQL?
- How to count unique domains from email address field in MySQL ?