Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate the difference between two dates and get the value in years? [duplicate]

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.

like image 388
Vishal Avatar asked Jun 30 '10 20:06

Vishal


People also ask

How do you calculate the difference in years between two dates?

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.

How do I calculate days difference between two dates and times in Excel?

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.

How do I subtract two dates in Excel?

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.


1 Answers

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.

like image 196
alexn Avatar answered Sep 19 '22 10:09

alexn