T
TJS
what namespaces are required so I can do a simple calculate age from date of
birth ?
birth ?
Chris Bower said:DateDiff is a function in the Microsoft.VisualBasic namespace.
Namespace MyFunctions
static class MyExtensions
private const double YEAR_CALC = 365.2425;
public static int Years(this TimeSpan ts) {
return (int)Math.Floor(ts.TotalYears());
}
public static double TotalYears(this TimeSpan ts) {
return ((double)ts.Days) / YEAR_CALC;
}
public static int Age(this DateTime dob, DateTime fromDate) {
TimeSpan ts = fromDate.Subtract(dob);
int age = ts.Years();
[COLOR="green"]//will never return negative years - if this is desired, [/COLOR]
[COLOR="green"]// just return age[/COLOR]
return Math.Abs(age);
}
}
}
using MyFunctions.MyExtensions;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.