I have a form with a box for the user to enter the date in the format dd/mm/yyyy. The latter appears in the box by default. I have a flag called $valid which is only true if the user replaces the default with numbers. The code I use works ok giving the day of the week also, but I’m sure from my knowledge of other languages that there is a more elegant solution. The flag is also required at a later stage.
[code=php]
$yyyy=substr($date,-4);
$mm=substr($date, 3, 2);
$dd=substr($date, 0, 2);
if (is_numeric($dd) and is_numeric($mm) and is_numeric($yyyy)) {
$valid=true ;
} else {
$valid=false ;
}
if ($valid) {
$date=date (“l d-M-Y”, mktime (0,0,0,$mm,$dd,$yyyy)); // formats & o/ps date
}