Mysql -- Last 30 days
Edit: Changed query as per OP
select * from cc_open_incident_viewWHERE date between (CURDATE() - INTERVAL 1 MONTH ) and CURDATE()
Previous Answer:
If date is saved as date
then use this
select * from cc_open_incident_viewWHERE date >= (CURDATE() - INTERVAL 1 MONTH )
If date is saved as string then use this (assuming it is in dd/mm/yyyy ...
select * from cc_open_incident_viewWHERE STR_TO_DATE(date ,''%d/%m/%y %h:%i:%s')>= (CURDATE() - INTERVAL 1 MONTH )
SELECT *FROM cc_open_incident_viewWHERE yourdatetimecolumn BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE()
Also note that CURDATE()
returns only the DATE
portion of the date, so if you store yourdatetimecolumn
as a DATETIME
with the time portion filled, this query will not select the today's records.
In this case, you'll need to use NOW
instead:
SELECT *FROM cc_open_incident_viewWHERE yourdatetimecolumn BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
If the datatype is datetime or timestamp (and you want to check the time):
SELECT * FROM yourtable WHERE yourdatetimeortimestampcolumn <= NOW() - INTERVAL 1 MONTH;
If your column datatype is date:
SELECT * FROM yourtable WHERE yourdatecolumn <= CURRENT_DATE() - INTERVAL 1 MONTH;
If your column is a string, you will need to convert it first by doing:
SELECT STR_TO_DATE('5/16/2011 20:14 PM', '%c/%e/%Y %H:%i');
http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_str-to-date