I am developing a website of e-voting system and i am facing some problem in validating age such that when voter's dob is entered then if age is less than 18 then he should not be eligible for registration, please suggest me how to do this.
comparing date in asp.net using vb
Collapse
X
-
Tags: None
-
Hey barkha nag, you can do like this for age validation.
Code:Dim BirthdayDate As DateTime = Convert.ToDateTime("Date of Birth") ' Month/Day/Year format Dim CurrentDate As DateTime = DateTime.Now Dim years As Integer = CurrentDate.Year - BirthdayDate.Year If CurrentDate < BirthdayDate.AddYears(years) Then years -= 1 End If If years < 18 Then ' Not eligible to register Else ' Register End IfComment
Comment