How to Get Last 15 Days Data in PHP MySQL?

Feb 16, 2022 . Admin

Hello Friends,

I am going to explain you example of how to get last 15 days data in PHP?. You will learn PHP query to get last 15 days data. I would like get last 15 days records in PHP. This article will give you simple example of PHP query to get last 15 days data.

We will use get search how to select last 15 days from news table using PHP. You can understand a concept of search how to take last 15 days dates from the current month in PHP. So, we can illustrate the getting a date 15 days in the past PHP.

You can see both example of how do I get my last 15 days data in PHP.

Table: users


So, let's see bellow solution:

index.php
<?php

$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "db_php";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

$sql = "SELECT 
            * 
        FROM `users` 
        WHERE DATE(created_at) >= (DATE(NOW()) - INTERVAL 15 DAY)";

$result = $conn->query($sql);

while ($row = $result->fetch_assoc()) {
    echo '<pre>';
    print_r($row);
}

?>
Output:
Array
(
    [id] => 2
    [name] => Aatman infotec
    [email] => aatmaninfo@gmail.com
    [created_at] => 2022-02-01 10:21:52
    [updated_at] => 2022-02-12 10:21:52
)
Array
(
    [id] => 3
    [name] => haresh
    [email] => hdsavani@gmail.com
    [created_at] => 2022-02-04 10:25:52
    [updated_at] => 2022-02-10 10:25:52
)
It will help you...
#PHP