The only thing I do in the query, which can probably be done in the code, is also convert datetimes to a user timezone.
The MySQL CONVERT_TZ () function is easy to use and accurate. I save all my data in UTC and retrieve it in a user time zone. The rules of saving summer time are changing. This is especially important for client applications, since using your own library depends on the fact that the user has updated his OS.
Even for server-side code, such as a web server, I need to update several tables to get the latest time zone information instead of updating the OS on the server.
Beyond these types of problems, it is probably best to distribute most of the functions to the application server or client, rather than making your database a bottleneck. Application servers are easier to scale than database servers.
If you can write a stored procedure or something that can start with a large dataset, do some inexpensive calculations or a simple iteration to return a single row or value, then it probably makes sense to do this on the server to save big ones from sending wire datasets. So, if the processing is inexpensive, why not return the database exactly what you need?
source share