-1

I have calculate age in view using something like this...

For example I have this in view:

 <dt>
     Age
 </dt>
 <dd>
     @(DateTime.Now - this.Model.dateofbirth)
 </dd>

but the result shows it to me in days, I want age in years. Thanks in advance!!!

1 Answers1

0

You can do this:

@(DateTime.Now - this.Model.dateofbirth).Year

Because both variables are Datetimes the subtract result will be Datetime which has a Year property.