Minimum age validation in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jens Jensen

    Minimum age validation in C#


    How do i verify that an age entered as dd-mm-yyyy is minum 21 today in C#?

    Any suggestion will be highly appreciated.

    JJ


  • Morten Wennevik

    #2
    Re: Minimum age validation in C#

    Hi JJ,

    DateTime d = DateTime.Parse( date);
    if(d <= DateTime.Now.Ad dYears(-21))
    // over or equal to 21 years


    On Mon, 09 Oct 2006 12:10:41 +0200, Jens Jensen <jj@jensen.dkwr ote:
    >
    How do i verify that an age entered as dd-mm-yyyy is minum 21 today in
    C#?
    >
    Any suggestion will be highly appreciated.
    >
    JJ
    >
    >


    --
    Happy Coding!
    Morten Wennevik [C# MVP]

    Comment

    • Champika Nirosh

      #3
      Re: Minimum age validation in C#

      cannot read your question well..

      Age entered as dd-mm-yyyy ??? probably date of birth

      if yes..

      then load it to a datetime object
      get the today date loaded to a date time object
      get the difference to a timespan object and it have the property you are
      looking for, years, months, days, hours etc

      Nirosh.

      "Jens Jensen" <jj@jensen.dkwr ote in message
      news:%23qzQus46 GHA.4552@TK2MSF TNGP05.phx.gbl. ..
      >
      How do i verify that an age entered as dd-mm-yyyy is minum 21 today in C#?
      >
      Any suggestion will be highly appreciated.
      >
      JJ
      >

      Comment

      • Jens Jensen

        #4
        Re: Minimum age validation in C#

        DateTime d = DateTime.Parse( date);
        if(d <= DateTime.Now.Ad dYears(-21))
        // over or equal to 21 years


        I like this solution.
        Many thanks
        JJ


        Comment

        Working...