Categories:

Home / Free JavaScripts / Math Related / Here

Cut & Paste Ultimate Age Calculator

Credit: JavaScript Kit

Description: This is your ultimate age calculator script! Use it to display the age of any person or past event, in a variety of units. Highlights of the script are:

  • Display the age in any one of the following units-"years", "months", or "days"

  • Specify the number of decimals to show

  • Specify whether to round up or down the age

  • Script can be invoked multiple times on the same page to calculate/display multiple ages.

Example:

JavaScriptKit.com is old!
has passed since the Millennium.
Bill Gates is old.

Directions

Step 1: Insert the following script in the <HEAD> section of your page:

Step 2: With the above script installed, you can now calculate and display the age of any item by invoking the function displayage(). Insert the following sample code in the <BODY> section of your page to see how to use this function:

Here's the lowdown on displayage():

//displayage (year, month, day, unit, decimals, rounding)
//year should be a valid full year (ie: 1978)
//month should an integer from 1 to 12
//day should be a valid day of the month
//unit specifies the unit to display the age in. Valid values are "years", "months", or "days"
//decimals specifies the number of trailing decimals. Valid values are 0 and above
//rounding specifies whether to round up or down the age. Valid values are "roundup" or "rounddown"


JavaScript Tools:
Site Info

CopyRight 1998-2014 JavaScript Kit. NO PART may be reproduced without author's permission.