DEV Community

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

Posted on • Edited on

1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay