Date_format return false when seconds are leading without zero
<p>I have a string coming in json message like this: "2016-2-16 13:48:<strong>3</strong>"</p>

<p>Note that the seconds are not leading with zero, and I need to validate that the date is in a correct format before inserting it into a database, </p>

<p>So I created a function to validate the date using date_format function like this:</p>

<pre><code>function validateDate($date, $format = 'Y-m-d H:i:s')
{
    $d = DateTime::createFromFormat($format, $date);       
    if ($d) {
        return $date;        
    } else {
        return null;
    } 
}
</code></pre>

<p>My problem when the seconds are not leading with 0 it return null, since the format does not have seconds without leading 0, so it the seconds should be like "03" instead of just "3", </p>

<p>Any ideas?</p>