How To Get Current Month Records In MySQL

Websolutionstuff | Feb-08-2022 | Categories : MySQL

In this tutorial, we will see how to get current month records in MySQL. For data analysis and reporting, we need more data or records. So, we will learn how to get current month data in MySQL PHP.

For getting data for the current month in MySQL we use the month() function. MySQL month() returns the month number for a given date. The return value is from 1 to 12.

So, let's see SQL query to get current month data, get current month data in laravel 6/7/8, how to get current month 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 MONTH(order_date) = MONTH(now())
       and YEAR(order_date) = YEAR(now());

In the above query, we use the now() function to get the current date, and the month() function to get the current month number of date values. 

 

 

How to Get New Users in the Current Month in MySQL

Using the below MySQL query you can get the new users in the current month with date and count.

select date(created_at), count(*) from users
       where MONTH(created_at) = MONTH(now())
       and YEAR(created_at) = YEAR(now())
       group by date(created_at);

 


You might also like :

Recommended Post
Featured Post
Feature Flag System in Laravel 11 for Controlled Releases
Feature Flag System in Laravel...

Hello, laravel web developers! In this tutorial, I will show you how to build a feature flag system in Laravel 11 that a...

Read More

Oct-09-2024

How to Generate QR Code in Node.js
How to Generate QR Code in Nod...

In this example we will see how to generate QR Code in Node.js application. In this example we will use qrcode npm...

Read More

Sep-20-2021

The Mix Manifest Does Not Exist Laravel
The Mix Manifest Does Not Exis...

In this article, we will see the mix manifest does not exist in laravel 8 and laravel 9. We will solve the mix...

Read More

Oct-28-2022

Laravel 11 Create CRUD Operation with Database
Laravel 11 Create CRUD Operati...

Hello developers! In this article, we'll learn about Laravel 11 to create Creat Reas Update Delete operations w...

Read More

Apr-08-2024