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

The Crack

Nightmare

Rawlings

Swimmers

Stop

For 50mm Christmas come earlier...

Dawn at the City of Arts and Sciences: Blue and Magenta series

freedom

Gold Coast <3

Untitled

More Photos

Leave your comment

Blog Stats

  • 118,000 hits