SiteKickr Web Development

MySQL – Query last months data

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.