Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
For suppose my company hires employees so that they are less than 30 years old.. if i Select date time picker my message box has to show that one's "age is this much" so you are not supposed to fit for this position,,, for this type of problems What to do..
Posted

Use the following C# Code:

DateTime dt1, dt2;
dt1 = System.DateTime.Now;
dt2 = Convert.ToDateTime(dateTimePicker1.Text);
int start, end;
start = Convert.ToInt32(dt1.Year);
end = Convert.ToInt32(dt2.Year);
if (start - end < 30)
{

}
else
{

}
 
Share this answer
 
Comments
George Jonsson 4-Sep-14 9:00am    
How about using dateTimePicker1.Value and TimeSpan instead.

TimeSpan tsAge = DateTime.Now - dateTimePicker1.Value;
if (tsAge.Year > 30)
// Show message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900