Looking to pull in data from your MySQL database according to a dynamic date range? We've got you covered!  

Here are some example snippets that you can add to your queries*:

*Replace any instance of  "DATE_COLUMN"  with the name of the date column / field you want to base the filter off of.

Last 30 Days

WHERE "DATE_COLUMN" >= DATE_FORMAT(CURDATE(), '%Y-%m-%d') - INTERVAL 30 DAY

MTD

WHERE MONTH("DATE_COLUMN") = MONTH(CURRENT_DATE())

YTD

WHERE YEAR("DATE_COLUMN") = YEAR(CURDATE()) 

Last Month

WHERE YEAR("DATE_COLUMN") = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
AND MONTH("DATE_COLUMN") = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)

Last Year

WHERE YEAR("DATE_COLUMN") = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))


If you have questions, feel free to email us or chat in on the site!

Did this answer your question?