I have a date input that requires the user to enter the date in the following format: DD-MM-YYYY – It is then converted to YYYY-MM-DD
I want to perform a check to see whether they are entering the correct format. i.e. if anything else is entered other than DD-MM-YYYY then it should produce an error message
Im currently using the following
list($y, $m, $d) = explode('-', $date);
if(checkdate($m, $d, $y)){
}else{
die("The date was in the wrong format");
}
I have tried putting the code that follows this inside the if statement, aswell as not including the else at all – but it does not work. Any suggestions on what i can try? Thankyou
You are asking the user to enter DD-MM-YYYY, but your
list()call expects theexplode()order as YYYY-MM-DD.Update your code to with: