Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey m a beginner in developing a windows desktop application n m stuck nw in validating the dates like birthday and all ..plz i need help !!

like :-
1)the date entered should be not less than 18yrs

2)the dates should be between 2 specific dates

plzzzz help me !!!
Posted

You can think about using the TimeSpan class[^] to calculate the difference between the two dates.

If you want to validate the date itself, think about using DateTime.TryParse.
 
Share this answer
 
Convert your date to a DateTime (or use the DateTimePicker and get a DateTime directly - it's a better solution)
You can then just check it:
C#
string date = "2/2/2013";
DateTime dt = DateTime.Parse(date);
if (DateTime.Now >= dt.AddYears(18))
    {
    // 18 or over...
    }
if (new DateTime(2011, 12, 31) < dt && dt < new DateTime(2014, 1, 1))
    {
    // In date period
    }
 
Share this answer
 

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