PDA

View Full Version : Age


chris-sharpe99
07-31-2003, 12:47 PM
I got this code from the site library my_date = new Date();
function date_to_age(my_year, my_month, my_day) {
mem = my_date.getTime();
my_date.setFullYear(my_year, my_month-1, my_day);
myage = my_date.getTime();
mem = mem-myage;
my_date.setTime(mem);
trace("years/age: "+(my_date.getFullYear()-1970)+" month: "+my_date.getMonth()+" days: "+my_date.getDate()+" by www.advance-media.com");
return (my_date.getFullYear()-1970);
}
age = date_to_age(1970, 7, 21);

and it works fine, but when I change it to

my_date = new Date();
function date_to_age(my_year, my_month, my_day) {
mem = my_date.getTime();
my_date.setFullYear(my_year, my_month-1, my_day);
myage = my_date.getTime();
mem = mem-myage;
my_date.setTime(mem);
trace("years/age: "+(my_date.getFullYear()-1989)+" month: "+my_date.getMonth()+" days: "+my_date.getDate()+" by www.advance-media.com");
return (my_date.getFullYear()-1989);
}
age = date_to_age(1989, 4, 3);
it says I'm -5. Can anyone see what went wrong, because as far as I can see it should work fine.
Chris

fgf
07-31-2003, 01:08 PM
Just scaning the code but
The 1970 is significant for the the date system used by flash. It the zero point for some time fucntions so I'm not sure changing that is gonna help matters. I think it may be hardcoded for a reason. I suspect you may have taken 19 years of your result

fgf

chris-sharpe99
07-31-2003, 01:10 PM
ok thanls, I'll try changing each one back.
Chris

chris-sharpe99
07-31-2003, 01:13 PM
Got it working with
my_date = new Date();
function date_to_age(my_year, my_month, my_day) {
mem = my_date.getTime();
my_date.setFullYear(my_year, my_month-1, my_day);
myage = my_date.getTime();
mem = mem-myage;
my_date.setTime(mem);
trace("years/age: "+(my_date.getFullYear()-1970)+" month: "+my_date.getMonth()+" days: "+my_date.getDate()+" by www.advance-media.com");
return (my_date.getFullYear()-1989);
}
age = date_to_age(1970, 4, 3);


Thanks fgf.
Chris

advance-media
08-02-2003, 11:38 AM
How interesting finding my code here.
please let me introduce myself, I'm the author of the script.
I'm sorry to have confused you because my birthday is in the year 1970 as well as the fix point of the date object.


only change the last line of the script like

age = date_to_age(1989, 4, 3);

if that is your birthday.
and don't change the first two -1970

cheers and show me your page if you have used the code. Just drop me a line! I'm curious!

Folko