I was given good direction to solve a problem today from here but I got stuck in trying to follow this direction.
I would like to retrieve a count for all rows from a table for the past 30 days using my date field. I populate these fields using now() and they are in the format Y-m-d h:i:s.
- I need a
countfor the rows added today, yesterday, 3 days ago…etc - I guess I can then use the above to get a count for each months?
- Finally a
countfor the year, year before etc using the months as total?
I was hoping not to specify dates in my query and for the query to just be generic and work out counts relative to today. I was hoping also I could do it accurately too by taking into consideration different months have different number of days.
How can I get this count using just SQL? I then can use the result set as an array and parse this with PHP.
Number of records inserted yesterday:
For the year:
And so on…