Results 1 to 2 of 2

Thread: converting date to age?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    8

    converting date to age?

    If you have a date, for example 06/12/78
    How can you get the age of a person who is born on that date?

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Here's what I use to calculate the age in C#
    Code:
    private int CalculateAge(string date)
    {
       DateTime d1 = Convert.ToDateTime(date);
       int age;
    			
       if(DateTime.Now.Month < d1.Month || DateTime.Now.Month == d1.Month && DateTime.Now.Month < d1.Day)
             age = DateTime.Now.Year - d1.Year - 1;
       else
             age = DateTime.Now.Year - d1.Year;
    
       return age;
    }
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

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