How to Get Current Month Records in PHP MySQL?
Feb 11, 2022 . Admin
Hello Friends,
I am going to explain you example of how to get current month records in PHP? , you will learn find current month records in PHP query. you will learn PHP get current month records from example. I would like to share with you PHP get current month records from timestamp.
Here, i will give you simple example of PHP query to get current month records. i will give you how to find PHP query to get current month data.
Here i will give you many example how to get records of current month 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 MONTH(created_at) = MONTH(now()) AND 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 infotec [email] => aatmaninfo@gmail.com [created_at] => 2022-02-08 10:21:52 [updated_at] => 2021-11-01 10:21:52 ) Array ( [id] => 3 [name] => haresh [email] => hdsavani@gmail.com [created_at] => 2022-02-11 10:25:52 [updated_at] => 2021-11-10 10:25:52 )It will help you...