Posts Tagged ‘Javascript

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

il paese che muore

ascend.

Rain

Villa Moderna

31/365 : Futile

Untitled

the journey

What's that smell? Methane....Party Trick!

ha! there's still some flowers lurking about

Day Three Hundred Nineteen

More Photos

Leave your comment

Blog Stats

  • 117,156 hits