2012-04-24 92 views
0

我有兩個datetimepickers(DateofBirth(DOB)和DateofIssue(DOI)),我需要驗證這些日期時間選擇器應該有18年的DateofBirth(DOB)和DateOfIssue(DOI)之間的差異。這個怎麼做。請建議我的想法日期時間選擇器驗證

回答

2
DateTime birth; 
DateTime issue; 
if (birth.AddYears(18) > issue) { 
    throw new Exception("Not 18 years between birth and issue"); 
} 
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;