Fatal error: Uncaught exception ‘Exception’ with message ‘DateTime::__construct():
<p>how do I resolve this issue.</p>

<p><a href="http://buddreambig.com/index.php" rel="nofollow">this is my site</a></p>

<p>this is the complete error.</p>

<blockquote>
  <p>Fatal error: Uncaught exception 'Exception' with message
  'DateTime::__construct(): Failed to parse time string (03-22-2016) at
  position 0 (0): Unexpected character' in
  /home/budweiser/public_html/verify.php:13 Stack trace: #0
  /home/budweiser/public_html/verify.php(13):
  DateTime->__construct('03-22-2016') #1
  /home/budweiser/public_html/verify.php(35): age('03-10-1991') #2
  {main} thrown in /home/budweiser/public_html/verify.php on line 13</p>
</blockquote>

<p>My code:</p>

<pre><code>&lt;?php
    //created date function
function age($dob){
    //echo $dob;
    $dob = date("m-d-Y", strtotime($dob));
    $date1 = new DateTime($dob);
    $date2 = new DateTime(date("m-d-Y"));
    $interval = $date1-&gt;diff($date2);
    return $interval-&gt;y;
}

    //if a form is submitted do the following
if(array_key_exists("submit", $_POST)){
    $mm = $_POST["date_"]["month"];
    $dd = $_POST["date_"]["day"];
    $yyyy = $_POST["date_"]["year"];

    $age = age($mm."-".$dd."-".$yyyy);
    //check age here
    if($age &gt; 17){
                    //set cookie here and redirect here if you want
        session_start();
        $_SESSION["old_enough"] = true;
        header('Location: http://91.109.247.179/~buddreambig/index.php');

    }else{
                    //redirect here as well
        include("verify-age.html");
    }
} else {
    include("verify-age.html");
}
?&gt;
</code></pre>

<p><strong>UPDATED CODE</strong></p>

<p><strong>NEW ERROR</strong> </p>

<blockquote>
  <p>Fatal error: Uncaught exception 'Exception' with message
  'DateTime::__construct(): Failed to parse time string
  (1970197019701970-JanJan-ThuThu) at position 7 (0): Double date
  specification' in /home/budweiser/public_html/verify.php:11 Stack
  trace: #0 /home/budweiser/public_html/verify.php(11):
  DateTime->__construct('197019701970197...') #1
  /home/budweiser/public_html/verify.php(35): age('--') #2 {main} thrown
  in /home/budweiser/public_html/verify.php on line 11</p>
</blockquote>

<pre><code>&lt;?php

    //created date function

function age($dob){

    //echo $dob;

    $dob = date("YYYY-MM-DD", strtotime($dob));

    $date1 = new DateTime($dob);

    $date2 = new DateTime("now");

    $interval = $date1-&gt;diff($date2);

    return $interval-&gt;y;

}



    //if a form is submitted do the following

if(array_key_exists("submit", $_POST)){

    $MM = $_POST["date_"]["month"];

    $DD = $_POST["date_"]["day"];

    $YYYY = $_POST["date_"]["year"];



    $age = age($YYYY."-".$MM."-".$DD);

    //check age here

    if($age &gt; 17){

                    //set cookie here and redirect here if you want

        session_start();

        $_SESSION["old_enough"] = true;

        header('Location: http://buddreambig.com/');



    }else{

                    //redirect here as well

        include("verify-age.html");

    }

} else {

    include("verify-age.html");

}

?&gt;
</code></pre>