- var_dump: documentation ( source)
<?php
$input_date = '2015';
$date = \DateTime::createFromFormat('Y-m-d', $input_date);
if (empty($date)) {
$date = \DateTime::createFromFormat('m/d/Y', $input_date);
if (empty($date)) {
throw new \Exception("Date field '$field' not in the required format (MM/DD/YYYY or YYYY-MM-DD).");
}
}
var_dump($date);