# coverting primitive date into the the month

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
LVL 19
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PluritechnicianCommented:
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;
}
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

System Architect, CF programmer Author Commented:
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
PluritechnicianCommented:
born in march to september 9 - 3 = 6
System Architect, CF programmer Author Commented:
different case when 15 years and 6 month

I will also have a rule for 16 years sharp
PluritechnicianCommented:
if you change the rules, change the code