For starters, I have a MySQL db with a field set to "date". I then have a form that you enter the date into - normally they are entering with this format m/d/Y (01/01/2006). I am using this snippet I have modified to reformat it to the standard Y-m-d (2006-01-01) format. The problem I am having is that it seems to be quite picky. Some dates go into the DB but some will not. Like 12/17/2006 will not go in . . . CRAZY . . . there are others but basically it works part of the time and not most of the time. Anyone know of another way to do this that is more stable?
//$replace_vars = array('/',);
$expire_date = $_POST['expire_date'];
$expire_date = str_replace('/', '-', $expire_date);
$date = $expire_date;
if (ereg ("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $date, $regs)) {
$x_date = "$regs[3]-$regs[2]-$regs[1]";
}