Shoumen Agdm Shoumen Agdm - 1 year ago 53
SQL Question

How do I find all data from a table in a specific month

I am trying to retrieve all data from table in a specific month, my date format in the database table is

I am need to find with the respect of a selected date, like if I select

it will retrieve
interval values from the table.

And also to all the values in this month which is
month, I am using
with PHP. I have tried using this query

SELECT * FROM t_tenancy_details WHERE
agreement_date >= DATE_FORMAT( CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01' )AND
agreement_date < DATE_FORMAT( CURRENT_DATE, '%Y/%m/01' )

This works fine for the running month, But problem is that if I select a previous month it does not work.

Answer Source

It looks you are asking for a real example try it

SELECT * FROM t_tenancy_details where MONTH(date) = MONTH('2016-05-01')
AND YEAR(date) = YEAR('2016-05-01')

This will select automatically 05 month form the date like also year too. and simply you can also make this input change as your wish.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download