Solved

# coverting primitive date into the the month

Posted on 2014-09-24
197 Views
I have the primitive date that I am calculating the by dividing by this formula 1000 * 60 * 60 * 24 * 365.25 so this will give me age of the person. Now I also want to get a month from this primitive date
0
Question by:erikTsomik
• 3
• 2

LVL 82

Accepted Solution

leakim971 earned 500 total points
ID: 40342475
Now I also want to get a month from this primitive date

store the number of year in a variable : yearAge
use :

``````function calcage() {
var vdob = new Date(document.getElementById("dateofbirth").value);
var vcurrentTime = new Date();
var vyear = vcurrentTime.getFullYear();
var ageInMilliseconds = vcurrentTime.getTime() - vdob.getTime();
var ageInYear = Math.floor(ageInMilliseconds / (1000 * 60 * 60 * 24 * 365.25));
var ageInYearMillisecond = ageInYear * 1000 * 60 * 60 * 24 * 365.25
var months = Math.floor((ageInMilliseconds - ageInYearMillisecond)/(1000 * 60 * 60 * 24 * 29.5));
document.getElementById("age").value = ageInYear + ' years' + " and " + months;
}
``````
0

LVL 19

Author Comment

ID: 40342605
I tried but the formula does not. FOr example the persons birthday is on 3/24/1999 so today he is exactly 15 years 9 month old, if I shift the date to 3/25/1998 then it is still shows me 15 years and 6 month event though his 15 years and 9 month will be tomorrow
0

LVL 82

Expert Comment

ID: 40342660
born in march to september 9 - 3 = 6
0

LVL 19

Author Comment

ID: 40342683
different case when 15 years and 6 month

I will also have a rule for 16 years sharp
0

LVL 82

Expert Comment

ID: 40342694
if you change the rules, change the code

Now I also want to get a month from this primitive date

line 8 you've the month :
var months = Ma...

what else?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…