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.?
Asked
Active
Viewed 461 times
-2
-
1What is your effort so far? – Tzu May 19 '15 at 16:32
1 Answers
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

CodeJrMasterX
- 23
- 3