0

我有两个日期时间选择器(DateofBirth(DOB) 和 DateofIssue(DOI)),我需要验证这些日期时间选择器,DateofBirth(DOB) 和 DateOfIssue(DOI) 之间应该有 18 年的差异。这个怎么做。请建议我的想法

4

3 回答 3

2
DateTime birth;
DateTime issue;
if (birth.AddYears(18) > issue) {
    throw new Exception("Not 18 years between birth and issue");
}
于 2012-04-24T08:11:40.147 回答
0
System.DateTime date1 = new System.DateTime(1996, 6, 3, 22, 15, 0);
System.DateTime date2 = new System.DateTime(1996, 12, 6, 13, 2, 0);

// diff1 gets 185 days, 14 hours, and 47 minutes.
int diff1 = date2.Subtract(date1).TotalYears;
于 2012-04-24T08:13:41.753 回答
0

使用DateDiff函数

http://msdn.microsoft.com/en-us/library/b5xbyt6f(v=vs.71).aspx

于 2012-04-24T08:13:51.880 回答