Hi, I want to validate as well as convert the users inputted date from the format 15/04/2016 to 15 Apr.
[php]
// check pickup date validation
// checks if user input and not empty
if(isset($_GET[‘pickup_date’]) && !empty($_GET[‘pickup_date’]))
{
$pickup_date = ($_GET[‘pickup_date’]);
}else{
die(“Please enter a valid pickup date.”);
}
[/php]
I need to add in validation to check if its in the required format. As well as converting the format to another format, as mentioned above.
A way I tried to do it, but keep get the die statement when entering a date like 15/04/1993?
[php]
// check pickup date validation
// checks if user input and not empty
if(isset($_GET[‘pickup_date’]) && !empty($_GET[‘pickup_date’]))
{
$date = ($_GET[‘pickup_date’]);
if(preg_match("/^(\d{2})-(\d{2})-(\d{4})$/", $date, $matches))
{
if(checkdate($matches[2], $matches[1], $matches[3]))
{
$pickup_date = ($_GET[‘pickup_date’]);
}
}else{
die(“Please enter the pickup date in the required format (dd/mm/yyyy).”);
}
$pickup_date = date(‘d D’, strtotime($_GET[‘pickup_date’]));
}else{
die(“Please enter a valid pickup date.”);
}
[/php]