Reputation: 7651
var formattedDate = new Date(parseInt(thisObj.Patient.DateOfBirth.substr(6)));
When i print my Date Object, i get this as output.
Wed May 04 2011 09:30:00 GMT+0530 (GMT+05:30)
How can i separate May, 04 and 2011 into separate variables like
var Month = May;
var Date = 04;
var Year = 2011;
How i can also check whether the Age of the person is below one year or not.
Upvotes: 0
Views: 144
Reputation: 2293
The object has many handy methods - use them.
getDate()
: returns the day of the month (from 1-31)getFullYear()
: returns the year (four digits)getMonth()
: returns the month (from 0-11)Upvotes: 5
Reputation: 57691
You can only access the numerical values, you have to format them yourself then. Use Date.getFullYear()
, Date.getMonth()
etc. See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date for documentation of this object.
You can compare dates by subtracting them:
alert(new Date() - formattedDate);
This will show the number of milliseconds between current date and formattedDate
. Now you only need to know the number of milliseconds in a year.
Upvotes: 2
Reputation: 10994
Try using these three:
formattedDate.getYear() .getMonth() .getDay()
Upvotes: 1