mysql get current month records from datetime – How to get current month data in php?

mysql get current month records from datetime using MySQL MONTH() function (range of 1 to 12 ( January to December)) syntax & Example

mysql get current month records from datetime

Get records of current month

SELECT *
FROM orders
WHERE MONTH(custm_date) = MONTH(CURRENT_DATE())
AND YEAR(custm_date) = YEAR(CURRENT_DATE())

In the above query, i use system function MONTH() to get current month and YEAR() to get current year.

get month from database php

echo 'Join Day' . date('d', strtotime($data['custm_date']));
echo 'Join Month' . date('m', strtotime($data['custm_date']));
echo 'Join Year' . date('Y', strtotime($data['custm_date']));

How to Get Records of Current Month in MySQL

mysql> select * from incomes;
+------------+------+--------+
| custm_date | sale | custms |
+------------+------+--------+
| 2022-08-28 |  300 |     10 |
| 2022-08-29 |  650 |     15 |
| 2022-08-30 |  650 |     12 |
| 2022-09-01 |  650 |     14 |
| 2022-09-02 |  150 |     20 |
| 2022-09-03 |  300 |     21 |
| 2022-09-08 |  582 |     15 |
| 2022-09-09 |  582 |     17 |
| 2022-09-06 |  650 |     12 |
| 2022-09-07 |  150 |     15 |
| 2022-09-08 |  300 |     12 |
| 2022-09-09 |  582 |     18 |
+------------+------+--------+

How to Get incomes Data of Current Month in MySQL

mysql> select * from incomes
       where MONTH(custm_date)=MONTH(now())
       and YEAR(custm_date)=YEAR(now());
+------------+------+--------+
| custm_date | sale | custms |
+------------+------+--------+
| 2022-09-01 |  650 |     14 |
| 2022-09-02 |  150 |     20 |
| 2022-09-03 |  300 |     21 |
| 2022-09-08 |  582 |     15 |
| 2022-09-09 |  582 |     17 |
| 2022-09-06 |  650 |     12 |
| 2022-09-07 |  150 |     15 |
| 2022-09-08 |  300 |     12 |
| 2022-09-09 |  582 |     18 |
+------------+------+--------+

SQL query to get records of current month in MySQL.

Read Also:  How To Import CSV File into MySQL using PHP

mysql> SELECT * FROM incomes
      WHERE custm_date >= (LAST_DAY(NOW()) + INTERVAL 1 DAY - INTERVAL 1 MONTH)
      AND custm_date <  (LAST_DAY(NOW()) + INTERVAL 1 DAY);
+------------+------+--------+
| custm_date | sale | custms |
+------------+------+--------+
| 2022-09-01 |  650 |     14 |
| 2022-09-02 |  150 |     20 |
| 2022-09-03 |  300 |     21 |
| 2022-09-08 |  582 |     15 |
| 2022-09-09 |  582 |     17 |
| 2022-09-06 |  650 |     12 |
| 2022-09-07 |  150 |     15 |
| 2022-09-08 |  300 |     12 |
| 2022-09-09 |  582 |     18 |
+------------+------+--------+

I hope you get an idea about mysql get current month records from datetime.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.