This should do it:
list($d, $m, $y) = explode('/', $datedue); $billdate = date('Ym-d', mktime(0,0,0,$m,$d,$y);
Or it could be without the date functions suggested by Gumbo:
list($d, $m, $y) = explode('/', $datedue); $billdate = "$y-$m-$d";
I would recommend using date , though if you suspect that you need to change the format in the future. There is no need to use a regular expression for simple separation. In this case, Explode will be much faster.
The regular expression ereg_ deprecated since PHP 5.3.0 and will be removed in PHP 6. For regular expressions, use the preg_ functions.
About hiding errors; you should never hide notifications during development, as they help you create better code. Without this notification, you would happily use ereg , and your application could break badly when the server is upgraded to PHP 6. But you can control the number of errors displayed using error_reporting () . Turning error_reporting when your site is live can be a good idea.
By the way, start accepting some answers if you find them useful.
Tatu Ulmanen
source share