Click here to Skip to main content
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 696
1 OriginalGriff 478
2 Tadit Dash 400
3 sanket saxena 337
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 3 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid