Solved

coverting primitive date into the the month

Posted on 2014-09-24
5
192 Views
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
0
Comment
Question by:erikTsomik
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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

0
 
LVL 19

Author Comment

by:erikTsomik
Comment Utility
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

by:leakim971
Comment Utility
born in march to september 9 - 3 = 6
0
 
LVL 19

Author Comment

by:erikTsomik
Comment Utility
different case when 15 years and 6 month

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

Expert Comment

by:leakim971
Comment Utility
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?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now