-2

I have date of birth stored in mysql database in string format of Like "02 December, 2014". I Have to calculate Age from this string in report viewer C#? How to write expression.?

1 Answers1

0
    public static string FindAge(string DateOfBirth)
    {
        DateTime Birthdate = new DateTime();
        DateTime.TryParse(DateOfBirth, out Birthdate);
        TimeSpan TempAge = DateTime.Now - Birthdate;
        int Years = (int)TempAge.TotalDays / 365;
        return Years.ToString();

    }

Here is a crude example to find years. You'll need to do the formatting you want. If you want the format in years/months/days, it becomes harder because month is a variable unit of measure (see this answer). Be more specific as to the format and solutions you've tried yourself so far (as Tzu said). This should help as a starting point though. :)

Community
  • 1
  • 1