coverting primitive date into the the month

Posted on 2014-09-24
Last Modified: 2014-09-25
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
Question by:erikTsomik
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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;

Open in new window

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
LVL 82

Expert Comment

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

Author Comment

ID: 40342683
different case when 15 years and 6 month

I will also have a rule for 16 years sharp
LVL 82

Expert Comment

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

the question was about having the month using your formula :
Now I also want to get a month from this primitive date

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

what else?

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Debugging Html 8 32
Timer on div 5 24
Json and ajax 1 22
Displayindividual error messages for each text field using php validation with jquery and ajax 6 55
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question