How to Get Current Year Records in PHP MySQL

Feb 11, 2022 . Admin

Hello Friends,

I am going to explain you example of how to get current year records in PHP?. You will learn get current year records PHP query. I would like to how to get current year data in PHP.

Here, i will give you simple example get current year data in PHP server. I will give you get current year data. This post will give you get current date records in PHP query.

Here i will give you many example get current year records 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 YEAR(created_at) = YEAR(now())";

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

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

?>
Output:
Array
(
    [id] => 2
    [name] => Aatman Infotech
    [email] => aatmaninfotech@gmail.com
    [created_at] => 2022-02-02 13:33:52.000000
    [updated_at] => 2020-09-30 13:33:52.000000
)
Array
(
    [id] => 3
    [name] => Haresh
    [email] => savanihd2@gmail.com
    [created_at] => 2022-02-07 06:46:08.000000
    [updated_at] => 2020-09-18 12:04:09.000000
)

It will help you...
#PHP