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));

Advertisements
Tags: , ,

One Trackback to “Converting stored MySQL dates into UK format”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: