PHP/MySQL dates

I have posted before as to a MySQL date, i.e. Y-m-d can be converted in a previous post here.

I found myself this evening in need of converting UK dates back into the MySQL format.

Now, the strtotime() function requires a MySQL-style date going in, so doesn’t work in the way I needed it to tonight.

Luckily I found the ukstrtotime() function online, which works great:

function ukstrtotime($str) {
return strtotime(preg_replace("/^([0-9]{1,2})[/. -]+([0-9]{1,2})[/. -]+([0-9]{1,4})/", "\2/\1/\3", $str));
}

This is then used in the following way:

$mysqldate = date('Y-m-d',ukstrtotime($ukdate));

Leave a Reply

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

*