计算两个日期之间的区别,并获得年的价值? [英] Calculate the difference between two dates and get the value in years?
问题描述
可能重复:结果
的如何计算某人&rsquo的;年龄在C#中
我想基本上计算雇员的年龄 - 因此,我们必须DOB每个员工,所以在
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.
推荐答案
你想计算岁的雇员?然后你可以使用这个片段(从 http://stackoverflow.com/问题/ 9 /怎么办-I-计算,某人的年龄,在-C ):
Do you want calculate the age in years for an employee? Then you can use this snippet (from http://stackoverflow.com/questions/9/how-do-i-calculate-someones-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.
这篇关于计算两个日期之间的区别,并获得年的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!