I need to generate a report based on date and time
.
My database table has payments recorded with amount
and created datetime
.
And, I need to group data like sum of payments from 9:30pm
yesterday to 9:29pm
today
(ie) instead of group by date(created_date). And then records between these time range
.
I have the last two months records in my payments table.
Any help will be appreciated.
Thanks
Just add 2.5 hours to each date/time. This is most easily represented at 150 minutes:
group by date(created_date + interval 150 minute)
Thanks for all the answers.
I ended up with this one - group by 24 hours
SELECT CONCAT( CONCAT(DATE(DATE_SUB(created, INTERVAL '21:30' HOUR_MINUTE)),
' 21:30:00') , ' - ' ,CONCAT(DATE(DATE_ADD(created, INTERVAL '2:30' HOUR_MINUTE)),
' 21:29:59') ) AS tintin, COUNT(*) FROM test GROUP BY DATE(DATE_SUB(created,
INTERVAL '21:30' HOUR_MINUTE)) ORDER BY DATE(created) DESC ;
got some idea from here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.