Mysql query to fetch current month data

Sometimes we need to show only current month data in the application ,so for easy handling the data we should use a Mysql query to fetch current month data.Let we check out how to do that using one MySQL query

See below the Mysql query to fetch current month data


SELECT *
FROM leads
WHERE MONTH(date) = MONTH(CURRENT_DATE())
AND YEAR(date) = YEAR(CURRENT_DATE())
// leads= Table Name
// date = date field name


Here we are fetching current month data using the feature MONTH(CURRENT_DATE()) and MONTH(date)

MONTH(CURRENT_DATE()) will result 8 (since current month is Aug)

Next feature we are using in Mysql query to fetch current month data is YEAR(date) and YEAR(CURRENT_DATE())

YEAR(CURRENT_DATE()) will result 2019 (since today is Aug 24 2019)

so actual Mysql query to fetch current month data will work like this

SELECT *
FROM leads
WHERE MONTH(date) = 9
AND YEAR(date) = 2019

so it will fetch all result form database table leads that having date field value is in august month