|
|
32 years 8 months 24 days
You are here: irt.org | Articles | JavaScript | Date and Time | 32 years 8 months 24 days Published on: Saturday 11th October 1997 By: Martin Webb IntroductionThis article will describe how to calculate the age in years, months and days of someone who supplies their birthdate. It will use the date input routines described in the previous article Blind Date. How old are you?The following HowOld() function works out the difference between the two dates represented by day, month, year and thisDay, thisMonth, thisYear. The HowOld() function relies on the first date being older than the second date. It uses simple addition and subtraction to calculate the difference, using borrowing to borrow from yearsold and monthsold where month is greater than thisMonth and where day is greater then thisDay. It returns an empty string if either the resulting yearsold is negative, or if yearsold, monthsold and daysold are all zero. It finally returns a formatted string along the lines of: Age - 3 years 2 months 1 day
The HowOld() function can be utilised as follows:
Which when run produces: Note, the above is not 100% accurate as it assumes that every month has 31 days. Working ExampleWhy not try it out the frame version yourself. You may be older than you think! Source CodeYou can view the source code of the four components: Feedback on '32 years 8 months 24 days'
View the profile on Martin Webb and the list of other Articles by Martin Webb. |
-- div -->
|