2012-04-24 7 views
0

私は2つのdatetimepickers(DateofBirth(DOB)とDateofIssue(DOI))を持っていますが、DateofBirth(DOB)とDateOfIssue(DOI)の間に18年の違いがあるはずです。これを行う方法。私のアイデアを提案してくださいdatetimeピッカーのバリデーション

答えて

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;