Possible Duplicate:
How do I calculate someone’s age in C#?
I want to calculate basically the age of employees - So we have DOB for each employee, So on the C# Side I want to do something like this -
int age=Convert.Int32(DateTime.Now-DOB);
I can use days and manipulate then get the age...but I wanted to know if there something I can use directly to get the number of years.
In a new cell, type in =DATEDIF(A1,B1,”Y”). The “Y” signifies that you'd like the information reported in years. This will give you the number of years between the two dates.
To find the number of days between these two dates, you can enter “=B2-B1” (without the quotes into cell B3). Once you hit enter, Excel will automatically calculate the number of days between the two dates entered. Note that Excel recognizes leap years.
Calculate the difference in daysType =C2-B2, and then press RETURN . Excel displays the result as the number of days between the two dates (104). Select cell D2. Excel adjusts the cell references automatically to include the correct values for each row.
Do you want calculate the age in years for an employee? Then you can use this snippet (from Calculate age in C#):
DateTime now = DateTime.Today; int age = now.Year - bday.Year; if (bday > now.AddYears(-age)) age--;
If not, then please specify. I'm having a hard time understanding what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With