.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Age Calculation in ASP.NET

Posted By:Athira Sreejith       Posted Date: February 02, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

Age Calculation in ASP.NET

 

 

int intYear=0;
intMonth=0;
intDate=0;
intYear = Convert.ToInt32(1985);
intMonth = Convert.ToInt32(06);
intDate = Convert.ToInt32(5);
DateTime dtt = new DateTime(intYear, intMonth, intDate);
DateTime td = DateTime.Now;
int Leap_Year = 0;
for (int i = dtt.Year; i < td.Year; i++)
{
if (DateTime.IsLeapYear(i))
{
++Leap_Year;
}
}
TimeSpan timespan = td.Subtract(dtt);
intDate = timespan.Days - Leap_Year;
int intResult = 0;
intYear = Math.DivRem(intDate, 365, out intResult);
intMonth = Math.DivRem(intResult, 30, out intResult);
intDate = intResult;
Response.Write("Hello dear! You are " + intYear.ToString() + " Year/s " + intMonth + " Month/s " + intDate + " Day/s");

 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend