Here is a funtion that I use.
A user can enter a date in any of the following ways:
01 01 03
01-01-03
1-1-03
01-1-2003
1-01/03
1/1 03  you get the idea...
This function will standardize the date and make sure it's valid. If invalid it 
returns "ERROR"
function fixdate($data){
 $aux[0]="";
 $aux[1]="";
 $aux[2]="";
 $z=0;
 for($i=0; $i<strlen($data); $i++) {
  if(is_numeric($data[$i])) {
   $aux[$z].=$data[$i];
  }
  else {
   $z++;
  }
 }
 if(strlen($aux[0])==1) {
  $aux[0]= "0".$aux[0];
 }
 if(strlen($aux[1])==1) {
  $aux[1]= "0".$aux[1];
 }
 if(strlen($aux[2])==2) {
  $aux[2]= "20".$aux[2];
 }
 $mdate= $aux[0]."/".$aux[1]."/".$aux[2];
 if(checkdate($aux[0], $aux[1], $aux[2])) {
  Return $mdate;
 }
 else {
  Return "ERROR";
 }
}//function
 Diana Castillo <[EMAIL PROTECTED]> wrote:If a user inputs a date into 
a form, what function can I use to validate
that he put in a valid date?
I want to use checkdate but that needs the date split up into day, month
year.
Anyone have an easy way of doing this?
Thanks,
Diana


Reply via email to