You can query last months data without involving your scripting language to manipulate dates. Using MySQL's built in date subtraction methods, this is made simple with a WHERE clause.

where month(ts_created) = month(now() - interval 1 month)
  and year(ts_created) = year(now() - interval 1 month)

This same approach can be used for any time period supported by MySQL.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *