Results 1 to 4 of 4

Thread: [2.0] computing age base on current date..

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    [2.0] computing age base on current date..

    using c#, how can i get my age base on the current date? my birthdate is 4/11/1972? the result should be 35? kindly help me pls?

  2. #2
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [2.0] computing age base on current date..

    You want to paste out whatever code you have so someone could fix it?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    Re: [2.0] computing age base on current date..

    int age;
    DateTime bday;
    DateTime cdate;
    bday = DateTimePicker1.Value;
    cdate = DateTimePicker2.Today;

    age = cdate - bday;

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2.0] computing age base on current date..

    Try something like
    Code:
    int years = DateTime.Now.Year - BirthDate.Year; 
    
    if (DateTime.Now.Month < BirthDate.Month || 
        (DateTime.Now.Month == BirthDate.Month && 
        DateTime.Now.Day < BirthDate.Day)) 
        years--;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width