How do I calculate someone's age?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
I want to calculate the year and month. But I do not know syntax. I can not divide out.

in View

        @{
               DateTime now = DateTime.Today;
               @(now - Model.DateOfBirth)/ (365.25 * 24 * 60 * 60 * 1000)
           }

I want results.(Ex.)

     Current Age : 20 year 8 month


Thanks for the help.
11 years ago
to calculate age

    int age = now.Year - birthDate.Year;
    if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) age--;
11 years ago
elaa1979 wrote:
to calculate age

    int age = now.Year - birthDate.Year;
    if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) age--;


I do not understand how to convert from Model.DateOfBirth a birthDate.
Please tell me the code.

Thanks.
11 years ago
I'm done. I use.

@T("Age") @(DateTime.Today.DayOfYear > Model.DateOfBirth.Value.DayOfYear ? DateTime.Today.Year - Model.DateOfBirth.Value.Year : DateTime.Today.Year - Model.DateOfBirth.Value.Year - 1) @T("Year") @(DateTime.Today.Month - Model.DateOfBirth.Value.Month) @T("Month")

Thanks.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.