DEV Community

Cover image for Retrieving 6-Month Data from MySQL using SQL Query
Uzeyr OZ
Uzeyr OZ

Posted on • Updated on

Retrieving 6-Month Data from MySQL using SQL Query

A simple mysql command to see records that have been processed in the last 6 months

SELECT * FROM records
WHERE date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);

Enter fullscreen mode Exit fullscreen mode

This query uses the CURDATE() function to get the current date, and then subtracts 6 months from it using the DATE_SUB function. The result is used as the lower bound for the date column in the WHERE clause, ensuring that only records with a date within the last 6 months will be selected.

Top comments (0)