I needed to create a simple function that calculated a person age using Javascript. The problem here is that the Date object in Javascript returns the time in milliseconds so we need to convert that to years, this is how.
var displayField;
var someonesBirthDate = someonesBirthDate;
var now = new Date();
var ms = now.valueOf() - someonesBirthDate.valueOf();
var minutes = ms / 1000 / 60;
var hours = minutes / 60;
var days = hours / 24;
var years = days/365;
displayField.DataValue = years;
Simple huh?














Cool
Impressed. May look at http://snippets.dzone.com/posts/show/623 to compare
thanx!
Not working dear !!!
I created an Excel spreadsheet that automatically calculates ages, in Column B, using a formula based on birthdays entered in column A. I use this for my whole family, dozens of rows, and I only have to enter the birthdays once. Every time I open or refresh the file, it recalculates the ages. If the birthday is in cell A1, the Excel formula for cell A2 is is =ROUNDDOWN((NOW()-A1) /365.25,0)
Could I use your elegant script in the .html file created from this spreadsheet? Would it automatically update the ages on refresh? The Excel file freezes the values when converted to HTML.
Thanks
JB
You can use it in any way you want.
If you manage to find a way of passing your rows values to the function parameters then it should work.
I dont really have experience doing that, so I cant help you there
Sorry
How to calculate the age through Date of Birth but the age is 24 year .