469,290 Members | 1,774 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

working out the age. Help needed urgently!

This is just simple stuff I know, but I need help with it please. As you can see below I have asked for the DOB to be entered, but how do I get it to work out the persons age from their DOB to todays date?

var canvas;
canvas = openGraphics();

var phrase;
phrase = "Your name:";

var phrase2;
phrase2 = "Your Date of birth:";

var phrase3;
phrase3 = "Your mobile number:";

var phrase4;
phrase4 = "your email address:";

var name;
name = prompt("Please enter your name");

var DOB;
DOB = prompt("Please enter your date of birth DD/MM/YY");

var mobile;
mobile = prompt("Please enter your mobile number");

var email;
email = prompt("Please enter your email address");

var message;
message = phrase + name;

var message2;
message2 = phrase2 + DOB;

var message3;
message3 = phrase3 + mobile;

var message4;
message4 = phrase4 + email;

canvas.drawString( message, 10, 10);

canvas.drawString( message2, 10, 30);

canvas.drawString( message3, 10, 50);

canvas.drawString( message4, 10, 70);

canvas.paint();
Mar 5 '07 #1
5 1423
acoder
16,027 Expert Mod 8TB
Use
Expand|Select|Wrap|Line Numbers
  1. var today = new Date();
then see this page to see how you can use the Date object,
Mar 5 '07 #2
mrhoo
428 256MB
DOB = prompt("Please enter your date of birth DD/MM/YY",'');

Expand|Select|Wrap|Line Numbers
  1. try{
  2.     var D=DOB.split(/\W+/);
  3.     for(var i=0;i<3;i++){
  4.         D[i]=Number(D[i]);
  5.     }
  6.     --D[1];
  7.     var age= new Date()- new Date(D[2],D[1],D[0]);
  8.     age= Math.floor(age/3.15576e10);
  9. }
  10. catch(er){
  11.     DOB = prompt("Enter digits for the day, month and year, separated by / characters",'');
  12. }
Mar 5 '07 #3
acoder
16,027 Expert Mod 8TB
MrHoo, let me guess, 3.15576e10 is the number of seconds in a millennium, right?
Mar 6 '07 #4
mrhoo
428 256MB
MrHoo, let me guess, 3.15576e10 is the number of seconds in a millennium, right?
Yes, but it is also the number of milliseconds in 365.25 days:
1000*60*60*24*365.25=31557600000
Mar 6 '07 #5
acoder
16,027 Expert Mod 8TB
Yes, but it is also the number of milliseconds in 365.25 days:
1000*60*60*24*365.25=31557600000
Aah, that makes more sense. Thanks.
Mar 6 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Kamliesh Nadar | last post: by
5 posts views Thread by el prinCipante | last post: by
4 posts views Thread by Joonshik Kim | last post: by
6 posts views Thread by crack.the.hack | last post: by
19 posts views Thread by uhdam | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.