Best would be DateTime::createFromFormat :
$date = DateTime::createFromFormat('d/m/Y', $uk_date); $errors = DateTime::getLastErrors(); if($errors['warning_count'] || $errors['error_count']) { // something went wrong, you can look into $errors to see what exactly }
If the parsing is successful, then you have a DateTime object that provides many useful functions. One of the most important is DateTime::format , which allows you to get data from an object, for example:
$year = $date->format('Y');
source share