I am trying to select the last 6 months of entries in a table, I have a column called datetime and this is in a datetime mysql format.
I have seen many ways using in
You can get last six month's data by subtracting interval of 6 month from CURDATE() (CURDATE() is MySQL function which returns Today's date).
SELECT * FROM table
WHERE your_date_field >= CURDATE() - INTERVAL 6 MONTH;
Or you can use BETWEEN operator of MySQL as Below:
SELECT * FROM table
WHERE your_date_field BETWEEN CURDATE() - INTERVAL 6 MONTH AND CURDATE();