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
Sign In
Register
AdSense Revenue
Active Members
Today
Nikhil Gaur
(70)
Nadheera V
(30)
samsuddin
(24)
Last 7 Days
Nikhil Gaur
(621)
Anil Kumar ...
(582)
Abhisek Panda
(445)
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 2008
Member Level:
Gold
Rating:
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
how to validate the checkedlistbox thru javascript
It is possible vbscript and javasript in same page
how to run sql before window is closed. URGENT. HELP!
assigning a value to label from javascript
reset a fileupload
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use