Craig Snowbarger wrote:
Hello,
I have found a javascript on the internet that lets a user choose a date from a graphical pop-up calendar which formats the date like this: "04-Jun-2001". I need to change that to a format that mysql can recognize like this: "20000604" (yyyymmdd). Does anyone know how to do that?
I figured it out! If anyone knows of a better way, please let me know! Thanks.
$t = "03-Jan-2001";
$patterns = array("/Jan/","/Feb/","/Mar/","/Apr/","/May/","/Jun/","/Jul/","/Aug/","/Sep/","/Oct/","/Nov/","/Dec/");
$replacement = array("01","02","03","04","05","06","07","08","09","10","11","12");
//convert month abbreviation to equivilant zero-filled number
$phase1 = preg_replace($patterns, $replacement, $t);
//convert "dd-mm-yyyy" to "yyyymmdd" so MySQL can use it.
ereg ("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $phase1, $regs);
echo "$regs[3]$regs[2]$regs[1]";