@biishmar that solution will group by a few seconds ago, 1 minute ago and so on; not what the OP asked for. In addition, you are getting PHP to do a lot of work that the database is more than capable of doing.
Tested with what, 10 records? What about 50, or 100, or 1000, or 10000, or 100000 records, are php functions is more fast than database in that case? What about memory?
@biishmar no mate that is not the way to go, my database has over 2 milion records
! And if you say that php its faster than mysql, you should be joking with us. Raw queries and caching are not helping much, imagine doing that on php!