Convert American date format to European and vice versa

This PHP script came up in a discussion I had today with Jon Whitlock, who’s from the other side of the pond (U.K.) It’s a nifty little regular expression that converts an American date (12/31/2006) into a European date (31/12/2006). It struck me as a neat little snippet that others could probably use.

Updated Code

As Scott mentioned in the comments, I have changed the snippet to put quotation marks around the second regular expression.

print ereg_replace(“([0-9]+)/([0-9]+)/([0-9]+)”,“\2/\1/\3“,$date);

As he described it, the first section of the ereg_replace statement takes the date and places it into three variables, 1,2,and 3. It then places those variables into a new string in the 2/1/3 pattern. That makes this a round trip function. Your European dates can get converted back to Yankee days as well.