In SQL, I can format the date field using the following:
SELECT article_name, DATE_FORMAT( article_date, '%b %e, %Y' ) AS my_date FROM tblArticles
The same thing can be done in PHP using:
echo date('M j, Y', strtotime($row['article_date']));
And in my page, there would be around 50+ items. So, in PHP I would loop through the records, format the date and print them. The formatting done via PHP could be avoided if I use the date_format() within the query itself.
So, among these two approaches, which one would you prefer(regarding performance) ?
My pages are likely to get several hit and this app would be hosted in a shared hosting. So, I am concerned with performance at the moment. I just don’t want to give more load to my server. 🙂
Thanks in advance..
Doing everything in SQL will probably be faster than doing in PHP, however you should profile the code to figure out the exact situation. There are also probably better places for you to optimize since this isn’t likely to be a performance bottleneck in your system. The best way to determine where to focus your optimizing attention is to profile your code. Otherwise, you risk optimizing things that don’t really make a difference.