Convert American date format to European and vice versa
Published 1 year, 6 months ago in PHP Digg ThisThis 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.
-
$date=’12/31/2006’;
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 roundtrip function. Your European dates can get converted back to Yankee days as well.
5 Responses to “Convert American date format to European and vice versa”
- 1 Pingback on Oct 16th, 2007 at 6:38 am
- 2 Pingback on Oct 17th, 2007 at 9:31 am

don’t seem to work as php script
> print ereg_replace(“([0-9] )/([0-9] )/([0-9] )”,\\2/\\1/\\3,$date);
should be: print ereg_replace(”([0-9] )/([0-9] )/([0-9] )”,”\\2/\\1/\\3″,$date);
Awesome! Although I used $3-$1-$2 (instead of the \\ notation)