Forums » .NET » ASP.NET »

# how to calculate age from date of birth in c#

Posted Date: 24 Dec 2008      Posted By:: mukul prady     Member Level: Silver    Member Rank: 3735     Points: 1   Responses: 2

i want to calculate age from date of birth

suppose the date of birth of some one is 10/06/1984. so today he is 23 years old.
so i want to print his age as 23
how to do this

# Responses

 #332369    Author: Deepika Haridas      Member Level: Gold      Member Rank: 8     Date: 24/Dec/2008   Rating:     Points: 6 Hi,private void button3_Click(object sender, System.EventArgs e){System.DateTime date2 = System.DateTime.Now;System.DateTime date1 = new DateTime(1980,07,06);long yrs;yrs = DateDiff(date1,date2);MessageBox.Show(yrs.ToString());}public long DateDiff(System.DateTime StartDate,System.DateTime EndDate){long lngDateDiffValue = 0; System.TimeSpan TS = new System.TimeSpan(EndDate.Ticks - StartDate.Ticks); lngDateDiffValue = (long)( TS.Days / 365);return (lngDateDiffValue);}Thanks & Regards,Deepika - Sr. EditorWebmaster, GujaratSpiderhttp://angeldeeps.blogspot.com/"Experience is the name everyone gives to his mistakes"

 #332423    Author: Pradeep M      Member Level: Silver      Member Rank: 1430     Date: 25/Dec/2008   Rating:     Points: 6 public void age() { DateTime dtDOB = new DateTime(1984, 10, 6); TimeSpan ts = DateTime.Now.Subtract(dtDOB); int years = ts.Days / 365; Response.Write(years.ToString()); }

Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.If required, refer to the URL of this page in your new post.

 Next : retrive whole data from database table and write it to text file Previous : Login failed for user sa Return to Discussion Forum Post New Message Category: ASP.NET

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John

### Online Members

Tony John
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India