0845 205 0292

Request A Free Website Analysis

Close

MySQL Date_Format()

June 10th, 2010 by

Part of SEO now is improving the time it takes for a webpage to download to the user’s computer – the quicker it loads, the better.

There are many ways to shave off a half second here, or half second there (for example place your common images into a sprite and place them using CSS as opposed to downloading them all one after another), but there is so much more that your can do!

We all know about placing as many (if not all) of our CSS and javascript into one or two files (as opposed to seven or eight), and only loading the javascript files at the bottom of the page instead of in the head tags is another way to speed up the download time.

That’s the easy stuff! What about the back end stuff? You can optimise database queries and squeeze out even more milliseconds!

For example, a MySQL database will store a date in a yyyy-mm-dd format. In order to display it in the standard dd-mm-yyyy format the standard approach is to get the date out of the database and using PHP, explode it then put it back together again the desired format.

There is a better way!

Date_Format() is a MySQL Function that can be used in a MySQL Query to, as the name suggests, format dates, e.g:

[cc]

SELECT DATE_FORMAT(‘date’,'%d / %b / %Y’) AS showdate FROM table ORDER BY date DESC

[/cc]

What this line of code is doing is fetching the date from table and formatting it into the dd / Mmm / yyyy format (for example ’04 / Jun / 2010′), ready for processing in our PHP script. Of course there are many ‘specifiers’ that can be used to customise the results as are required by your script, for example %D will show the day of the month with the English suffix (0th, 1st, 2nd, 3rd, etc). As a side-note, ranges for the month and day specifiers begin with zero due to the fact that MySQL allows the storing of incomplete dates such as ’2014-00-00′.

For a full list of specifiers for the Date_Format function, visiting the MySQL Date and Times Reference Manual.

There’s a whole chapter in the MySQL Reference Manual dedicated to optimising which is definately worth reading, as squeezing every little bit of performance out of the database can help.

This entry was posted on Thursday, June 10th, 2010 at 4:32 pm . RSS GlobeYou can follow any responses to this entry through the RSS feed.

Link to us

If you want to link to this blog, copy and paste the following HTML code to your website.

2 Responses to “MySQL Date_Format()”

  1. Philip Hero says:

    I truly liked this article, this one is certainly going towards my stumble upon account :)

  2. Gerard says:

    http://www.mysqlformatdate.com is a great website for helping you format date with the date_format function in mysql

Navigation

Blog Categories

Free SEO Analysis & Proposal

From The Blogread news

  • FEB 13
    I've spent a bit of time recently covering the Facebook SEC S-1 filing that has been made in preparation for their IPO, including 5 of the most significant risk factors that Facebook faces.  In this blog I'd like to focu...
  • FEB 12
    Link building is still a process integral to any search engine optimisation campaign.  While the school of thought that social media marketing is the new link building is relatively well established, there is still a pla...

Latest Newsread news

  • FEB 10
    A Study was recently carried out by a US not for profit Research Company called Pew Internet, the survey revealed that the majority of users who engage in social media sites on a regular occurrence have a positive experiences and ...
  • FEB 07
    It has been recently announced of a relatively new feature for Yahoo search. Yahoo has recently launched a mobile app search tool in the UK, which is much later than the USA launch in June 2011. The feature itself, much like a...

Clients Say...

"We've long been considering an SEO campaign and have researched the benefits that it could potentially bring to our web presence," commented 3663 Catering Equipment's Managing Director Paul Knight. "The team at Click Consult put together a very attractive package and we're pleased to be able to enter into a sound business partnership with them. We're looking forward to seeing the results they can provide for the 3663 Catering Equipment website moving forward."

3663

Managing Director - 3663 Catering

"We have been working with Click Consult for over a year now. We are delighted with the increase in unique visitors to our site and they have far exceeded our conversion KPI metrics for customer database registrations. We rank in the top 3 for all keywords that we asked Click Consult to optimize for us. This agency know how to produce results."

hills pets

Managing Director - Liverpool One

"Whilst we have a long term keyword strategy, Click Consult have a good appreciation of our business and have a flexible approach to implementing short term keyword strategies to coincide with the peaks of the retail calendar. I receive a monthly performance report from Click Consult detailing the relevant data I require but in addition, I can review the work being undertaken at any time by logging in to their bespoke reporting system."

hills pets

CRM Manager - Liverpool One

"Hills has been looking for an agency that is able to quickly deliver in the search marketing area and catapult EMEA websites ahead of the competition. Taking SEO Consult for this project turned out to be a smart choice. Not only have they managed to significantly increase search engine traffic to our websites, but they also come with innovative ideas that can be turned to reality. I can simply say they deliver. And it's always a pleasure talking to them."

hills pets

Managing Director - Hills Pets