Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
plz help me i want to calculate date of birth select date from database then subtract to current date then show in textbox in asp.net application
Posted
Comments
R. Giskard Reventlov 1-Jun-12 18:51pm    
What have you already tried?
Sergey Alexandrovich Kryukov 1-Jun-12 19:54pm    
Is it a question? Not clear what kind of help you expect.
--SA

To calculate a person's age from their date of birth, you need to subtract their birth year from the current year and then determine if their birthday has past or not. The way I would do this would be to do the year calculation first and then add that number of years to the persons date of birth. Then I would compare that new date against the current date to determine if their birthday has past yet (if new date is less than or equal to now then they have had their birthday). If they have not had their birthday, I would subtract one from our year calculation.

There are a bunch of other ideas on Stack Overflow that might give you other options:

http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c[^]

That should get you going. Now you just need to pull the data from the database, do this comparison, and then display the results on your ASP.NET page.
 
Share this answer
 
you can all do in sql query

SQL
select dob,datediff("YY",dob,getdate()) as age from TableName where .... 
 
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