How to calculate age using TimeSpan w/ .NET CF?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone pls point me to or recommend the easiest way to calculate
someone´s age using the TimeSpan object, in .NET CF?

Isn´t there a simple way to use the TimeSpan object to calculate the elapsed
time and somehow convert the days to years w/out using the VB DLL?

Thanks.
 
charliewest said:
Can someone pls point me to or recommend the easiest way to calculate
someone?s age using the TimeSpan object, in .NET CF?

Isn?t there a simple way to use the TimeSpan object to calculate the elapsed
time and somehow convert the days to years w/out using the VB DLL?

What's wrong with the normal non-CF way of taking today's date (as a
DateTime) and their birthdate (likewise), then subtracting one from
another to get a TimeSpan?
 
hi
DateTime d1=DateTime.Now ;
DateTime d2 = new DateTime(1978,4,5);
TimeSpan difference = d1.Subtract(d2);

difference.TotalDays/365.25).ToString() will give you the years diffrence

regards
Ansil
 
There´s nothing wrong w/ the normal way if you know how ;-). Unfortunately, i
have been pampered by things like DateDiff. Obviously, dividing by
DaysPerYear is an option, however, i did want to check if there are
"built-in" functions that calculate this. Thanks.
 
charliewest said:
There?s nothing wrong w/ the normal way if you know how ;-). Unfortunately, i
have been pampered by things like DateDiff. Obviously, dividing by
DaysPerYear is an option, however, i did want to check if there are
"built-in" functions that calculate this. Thanks.

DateTime birthday = ...;

TimeSpan age = DateTime.Today - birthday;

Then look at whatever you're interested in within the "age" value.
 
Hi Ansil - I like your answer but what if you want to report the age in
Years, Months, Days??
G
 
Back
Top