Converting stored MySQL dates into UK format

You will no doubt be aware that when you save a date in a MySQL database, it must be in the form of Y-m-d.

I had some difficulty wrestling with the date() section of the PHP manual , and experimented for a few minutes on trying the use the SQL SELECT statement itself to get the date data from the database in my preferred UK (d/m/Y) format without sucess.

I was quite pleased therefore when my perseverance paid off, and I was able to work out how to solve my problem with a single line of PHP code:

$ukdate = date('d/m/Y',strtotime($mysqldate));

Leave a Reply

Your email address will not be published. Required fields are marked *

*