How To Get Last 15 Days Records In MySQL

Websolutionstuff | Feb-09-2022 | Categories : MySQL

In this tutorial, we will see how to get the last 15 days records in MySQL PHP.  In PHP, you can use INTERVAL to get the last 15 days record from the database table. For MySQL query, we use the INTERVAL operator. It is mainly used to calculate the date and time values. 

So, let's see SQL query to get last 15 days records, get 15 days data in laravel 6/7/8, how to get last 15 days data in PHP from MySQL Database.

MySQL Example :

Using SQL query to get data for the current month in MySQL.

id | order_date | amount | Orders
---+------------+--------+-------
 1 | 2022-02-01 | 150    | 2
 2 | 2022-02-02 | 200	 | 4
 3 | 2022-03-03 | 100	 | 1
 4 | 2022-03-04 | 300	 | 5
 5 | 2022-04-05 | 200 	 | 3
 7 | 2022-04-06 | 190	 | 7

 In your table, the record needs to be like date and month.

select * from users
       where order_date > now() - INTERVAL 15 day;

In the above query, we use the now() function to get the current date, and the INTERVAL() function to get the last 15 days records.

 

 

How to get new users in the last 15 days in MySQL

Using the below MySQL query you can get the new users in the last 15 days.

select * from users where created_at > now() - INTERVAL 15 day;

 


You might also like :

Recommended Post
Featured Post
Laravel 8 Order By Query Example
Laravel 8 Order By Query Examp...

In this example we will see laravel 8 order by query example. how to use order by in laravel 8.The orderBy met...

Read More

Dec-01-2021

How To Integrate Swagger In laravel 10
How To Integrate Swagger In la...

In the dynamic realm of modern web development, ensuring that APIs are well-documented, easy to comprehend, and seamless...

Read More

Aug-18-2023

How to Add and Delete Rows Dynamically using jQuery
How to Add and Delete Rows Dyn...

In this article, we will see how to add and delete rows dynamically using jquery. Also, we will see without&nb...

Read More

Jan-02-2021

How to Install PHP PDO MySQL Extension in Ubuntu 22.04
How to Install PHP PDO MySQL E...

Hey there! If you're diving into PHP development on Ubuntu 22.04 and need to connect your applications to MySQL data...

Read More

Feb-28-2024