Click here to Skip to main content
11,716,938 members (86,992 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 4:24am
Rate this: bad
good
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
    }
  Permalink  
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 719
1 F-ES Sitecore 235
2 Maciej Los 185
3 OriginalGriff 175
4 Richard MacCutchan 130
0 Sergey Alexandrovich Kryukov 1,029
1 Maciej Los 464
2 Richard MacCutchan 430
3 CHill60 415
4 OriginalGriff 415


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 3 Feb 2013
Copyright © CodeProject, 1999-2015
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