C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » JavaScript »

calculate age in javascript


Posted Date: 04 Jul 2008      Posted By: Meera      Member Level: Gold     Points: 1   Responses: 1



i have a calender control which gives me date in "dd/mm/yyy" format.

I am able to calculate age in years...i want age + months..

Please tell me how do i go about it.....

here is my logic to calculate age :

myDOB = txtDate.value.split('/');
myDate = myDOB[0];
myMonth= myDOB[1];
myYear = myDOB[2];

var age;
var now = new Date();
var todayDate = now.getDate();
var todayMonth = now.getMonth();
var todayYear = now.getYear();
if(myDate <= todayDate)
{
if(myMonth <= todayMonth)
age = todayYear-myYear;
else if(myMonth>todayMonth)
age = todayYear - myYear-1;
}
else if(myDate > todayDate)
{
if(myMonth < todayMonth)
age = todayYear - myYear -1;
else
age = todayYear - myYear -1;
}
alert(age);


Please tell me how do i calculate months by this logic





Responses

Author: sappi    04 Jul 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 3

try like this

if(myMonth <= todayMonth)
age = todayYear-myYear;
else if(myMonth>todayMonth)
age = todayYear - myYear-1;
months = 12-(mymonth-todaymonth)



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 : how to call a proxy class method from jscript
Previous : javascript function enable,disable the textbox, if i click a checkbox?
Return to Discussion Forum
Post New Message
Category: JavaScript

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use