Click here to Skip to main content
13,354,886 members (70,299 online)
Rate this:
Please Sign up or sign in to vote.
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 3-Feb-13 5:24am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 3 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100