Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i am using windows application
C#
 textbox1.text=date of birth
textbox2.text=current date;
text box3.text=age


how to calculate two date time picker.. value
Posted
Updated 30-Nov-11 19:55pm
v2

Use something like the following where dateofbirth is a DateTime:
C#
int age = DateTime.Now.Subtract(dateofbirth).TotalDays / 365;


Or
C#
int age = DateTime.Now.Year - dateofbirth.Year;
 
Share this answer
 
v2
Try this code :
VB
Public Function CalculateAge(ByVal BirthDate As Date)
'Return Yere Difference between Two Dates
Return  DateDiff(DateInterval.Year, Date.Now.Date, BirthDate)
End Function

Call this function where you want to calculate age
VB
Dim bd As Date=New Date("1/12/2010")
CalculateAge(bd)

I hope it will help you. :)
 
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