Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to select on DOB and automatically generates his AGE in textbox...
Posted

C#
DateTime dt = Calendar1.SelectedDate;
       DateTime dt1 = Convert.ToDateTime(DateTime.Now.ToShortDateString());
       TimeSpan t = dt1.Subtract(dt);
       TextBox1.Text = t.TotalDays.ToString();
       TextBox2.Text = (t.Days / 365).ToString();
 
Share this answer
 
Comments
Member 9993510 20-Apr-13 6:02am    
thank u very much sir........ its run
vinayakJJ 20-Apr-13 6:04am    
my pleasure
 
Share this answer
 
C#
// birthdate
        DateTime birthdate = new DateTime(1989, 1, 1);
        TimeSpan dur = DateTime.Now.Subtract(birthdate);

        int noOfdays = dur.Days;

        int noYear = noOfdays / 365;
        int noMonth = noOfdays % 365 / 30;
        int days = noOfdays % 365 % 30;

        //result
        string Info = noYear + " years " + noMonth+ " month "+days+" days";
 
Share this answer
 
try for this:-

DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if (bday > today.AddYears(-age)) age--;


or

int age = new DateTime(DateTime.Now.Subtract(birthday).Ticks).Year-1;
 
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