Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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
Comments
[no name] 1-Aug-12 10:07am    
You mean like the TimeSpan class?

try the code inside method. You can test it in console application
C#
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();
        }

    }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900