[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference abbott::java

Title:JAVA
Moderator:KOALA::CIOT
Created:Mon Nov 13 1995
Last Modified:Wed Jun 04 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:236
Total number of notes:1251

207.0. "How to calculate the exact age in Javascript?" by CECAMO::SALEM_H () Mon Feb 17 1997 08:33

Hi,

I had a problem calculating the exact age in Javascript.
Given a date : how to calculate the exact age? What i did
is to convert both now:Date and birthday:Date to seconds then 
extract them. the problem now is no "mod" function to extract the
exact nomber of years, months ...etc. Did i miss some functions or
methods?

Thanks for any hint.

P.S. Calculating field by field is not really helping such as :
     Nodays = now.getDay() - birthday.getDay();

Hussein SALEM
T.RTitleUserPersonal
Name
DateLines
207.1Subtract the years, compare the daysWIBBIN::NOYCEPulling weeds, pickin' stonesMon Feb 17 1997 16:2617
Here's how I do it in DCL:

$ y = f$cvtime(p1,,"year")
$ t = f$cvtime("",,"year")
$ a = f$integer(t)-f$integer(y)
$ if f$extract(5,99,f$cvtime("")) .lts. f$extract(5,99,f$cvtime(p1)) -
  then a = a-1
$ write sys$output a


Example:

$ @age 15-jul-1954
42
$ @age 15-jul-54
-58		(oops!)

207.2CECAMO::SALEM_HTue Feb 18 1997 04:536
Thanks for your reply .. i can do it in other languages like C/C++
even Java but i miss some functions in Javascript and that was my question.

Thanks any way.

Hussein SALEM
207.3CECAMO::SALEM_HTue Feb 18 1997 06:355
I found it, it is Math.round();

Thanks for all/

Hussein