I'm really stuck with calculating date of birth given a persons age in months. Currently, I'm using C# to do that. However, failed to understand the logic. Thanks in advance
Asked
Active
Viewed 286 times
-7
-
5Can you post the logic that you did not understand? And what is the area where you have a problem? – Ravi Y Dec 26 '12 at 09:01
-
Like if I'm provided a persons age in years. I can simply subtract it from the current year and assign the current date and month as part of the date of birth - that's what my project team accepted! But, the same logic could not be applied for age in terms of Month. Eg. someones' age is 18 months. – aby Dec 26 '12 at 09:07
-
So what prevents you from subtracting months from a given DateTime object? – Ravi Y Dec 26 '12 at 09:11
1 Answers
2
DateTime has perfect method to substract (actually add negative value) months from current date. For example:
int ageInMonths = 18;
DateTime dt = DateTime.Today;
DateTime DateOfBirth = dt.AddMonths(-ageInMonths);

Nogard
- 1,779
- 2
- 18
- 21