Calculate Age from date stored in database in Y-m-d using Laravel 5.2
<p>Hi User's add their DOB through the Form that store in database,</p>

<p>I would like calculate age from stored date in the database which is in this format Y-m-d,</p>

<p>My Question is :</p>

<ul>
<li><p>How to calculate Age?</p></li>
<li><p>Where to put the logic , In Controller or Model?</p></li>
<li><p>How to pass the stored Date in view in this format 'm-d-Y'</p></li>
<li><p>How to pass the result of logic which is age in view.</p></li>
<li><p>I am using something as below in my model is this Right?</p></li>
</ul>

<p>This is controller:</p>

<pre><code>public function index()   {   
    $profile   = User::find($this-&gt;userid())-&gt;profiledetailsHasOne;  //This has Dob field                   
    return view('profile.index',['profile' =&gt; $profile ]); 
}
</code></pre>

<p>This is my Model:</p>

<pre><code>public function getAge(){
    $this-&gt;birthdate-&gt;diff($this-&gt;attributes['dob'])
    -&gt;format('%y years, %m months and %d days');
}
</code></pre>

<p>This is my View:</p>

<pre><code>&lt;tr&gt;
    &lt;th&gt;Age&lt;/th&gt;
    &lt;td&gt;{{$profile-&gt;getAge()}}&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>Is this Right? I am getting error as below</p>

<blockquote>
  <p><code>Call to a member function diff() on null</code></p>
</blockquote>