ItSolutionStuff.com

How to Get Last 2 Days Records from Table using MySQL Query?

By Hardik Savani • June 13, 2023
MySql

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.

Query:

SELECT * FROM `elements`

WHERE created_at >= ( CURDATE() - INTERVAL 2 DAY )

I hope it can help you...

Tags: MySql
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Last Record in Codeigniter?

Read Now →

MySQL Query to Get Current Year Data Example

Read Now →

Trigger on After Delete with Update Query MySQL Example

Read Now →

MySQL Query to Get Current Month Data Example

Read Now →

MySQL Query to Remove Numbers from String in a Column Example

Read Now →

MySQL Query to Remove Special Characters from String

Read Now →

How to Add MySQL Trigger from Migration in Laravel?

Read Now →

How to Import CSV File using MySQL?

Read Now →

How to fetch this week records in MySql ?

Read Now →

Laravel Change Date Format using Carbon Example

Read Now →

How to Check Empty or Null Data using MySQL Query?

Read Now →

How to Copy One Table Data into Another Table using MySQL?

Read Now →

How to count unique domains from email address field in MySQL ?

Read Now →