Fetching PHP data by date for last 7 days from mysql database with different date layout
I have a transaction table in my database, where the data is stored in the date
following manner: 2014-08-30 02:22:35
.
I am doing some basic analytics and should be able to display all transactions for each day for the last 7 days, but I am a little confused as to how I can achieve this when there is a timestamp along with the date stored in the same field.
Any suggestions are greatly appreciated.
source to share
You can get the last seven days with:
where `date` >= CURDATE() - interval 7 day
This will return seven days, ignoring the time field.
I'm not sure what you mean by "displaying all transactions for each day for the last 7 days." You can retrieve just date
for a field using date
(sic, date(date)
) and use the value for filtering, aggregating or sorting.
source to share