Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello!!!!
Co-ordinates i want to solution that user give his/her DOB(Date Of Birth) and he/she want to see his/her actual age according to current date..... how can i get actual age format on(dd/mm/yy) subtracted from the current date...
AnyAnswer....????
plz i am seeking ur appreciation.
Posted 1-Aug-12 5:00am
Comments
Wes Aday at 1-Aug-12 10:07am
   
You mean like the TimeSpan class?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try the code inside method. You can test it in console application
class Program
    {
        static void Main(string[] args)
        {
            DateTime DOB = Convert.ToDateTime("1988-08-02");
            DateTime now = DateTime.Today;
 
            int age = now.Year - DOB.Year;
            if (DOB > now.AddYears(-age))
                age--;
            int month = now.Month - DOB.Month;
            int datediff = 0;
            int days = now.Day - DOB.Day;
 
            while (days < 0)
            {
                datediff += 1;
                days += 1;
            }
            string str = (31 - datediff) + "/" + month + "/" + age;
 
            Console.WriteLine(str);
            Console.ReadLine();
        }
 
    }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2014
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