Posts Tagged ‘Client side programming

16
Nov
07

Calculate someones age with Javascript

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?




 

November 2009
M T W T F S S
« Mar    
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Flickr Photos

Poetry in Motion (drawing in pastel)

Orchy trees

Tokyo Highway Sunset

an autumnal evening, downtown pdx

Day 182: OHHH SHIIIIIIIIII(N)

emotional landscape

Wild West

fence iii

Day Three Hundred Eighteen

dead end

More Photos

Leave your comment

Blog Stats

  • 117,005 hits