Solved

Javascript to calculate age in years

Posted on 2007-11-15
5
1,840 Views
Last Modified: 2012-06-27
We use a hosted database product that allows us to create custom fields based on formulas.  I created one that should calculate someone's age based on their birthday.  

Right now I have this:

round(ABS ({today}-{custitem_birthdate})/365.25)

It works except that the age gets rounded up if it's over 6 months through the year.  I can't run a full script, so I'm hoping there's some easy way to remove the decimal places without using 'round'.  Any help is much appreciated.
0
Comment
Question by:BasilFawlty001
  • 4
5 Comments
 
LVL 1

Accepted Solution

by:
Sahmeepee earned 350 total points
ID: 20292853
You could use Math.floor like:
Math.floor(ABS ({today}-{custitem_birthdate})/365.25)

Open in new window

0
 

Author Comment

by:BasilFawlty001
ID: 20293023
I can't seem to use that function.  Below is a list of math functions that are allowed.  Could I change the number to test and then trim the left 3 characters (decimal and decimal numbers)?


ABS ABS(n) returns the absolute value of n
ACOS ACOS(n) returns the arc cosine of n
ASIN ASIN(n) returns the arc sine of n
ATAN ATAN(n) returns the arc tangent of n
ATAN2 ATAN2(n1 { , | / } n2) returns the arc tangent of n1 and n2
BITAND BITAND(expr1, expr2) computes an AND operation on the bits of expr1 and expr2
CEIL CEIL(n) returns smallest integer greater than or equal to n
COS COS(n) returns the cosine of n
COSH COSH(n) returns the hyperbolic cosine of n.
EXP EXP(n) returns e raised to the nth powe
FLOOR FLOOR(n) returns largest integer equal to or less than n.
LN LN(n) returns the natural logarithm of n,
LOG LOG(n2, n1) returns the logarithm, base n2, of n1
MOD MOD(n2, n1) returns the remainder of n2 divided by n1
NANVL NANVL(n2, n1) returns an alternative value n1 if the input value n2 is not a number
POWER POWER(n2, n1) returns n2 raised to the n1 power
REMAINDER REMAINDER(n2, n1) returns the remainder of n2 divided by n1
ROUND (number) ROUND(n [, integer ]) returns n rounded to integer places to the right of the decimal point
SIGN SIGN(n) returns the sign of n
SIN SIN(n) returns the sine of n
SINH SINH(n) returns the hyperbolic sine of n
SQRT SQRT(n) returns the square root of n
TAN TAN(n) returns the tangent of n  
TANH TANH(n) returns the hyperbolic tangent of n
TRUNC (number) TRUNC(n1 [, n2 ]) returns n1 truncated to n2 decimal places
0
 

Author Comment

by:BasilFawlty001
ID: 20293028
That should have read "change the number to text".
0
 

Author Comment

by:BasilFawlty001
ID: 20293147
I think that this might be in the wrong section.  I'm no programmer and can't tell the difference between languages.  This is using SQL functions on an oracle database.
0
 

Author Comment

by:BasilFawlty001
ID: 20293462
Got it!  I just used floor(ABS ({today}-{custitem_birthdate})/365.25) without the math bit at the beginning.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

759 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

21 Experts available now in Live!

Get 1:1 Help Now