View Full Version : Help needed for event counter

06-22-2009, 11:42 AM
Hi - I am developing a birthing website and would like to include a counter that indicates how many babies have been born in the world in 2009. The global birth rates are 236 per minute or 3.94 per second. Can anybody help with a script that would be able to display this information.
Thank you.

Philip M
06-22-2009, 12:17 PM
Here you are:-

<div id = "babies"></div>

<script type = "text/javascript">

var basisDate = new Date(2009,0,1).getTime(); // January 1st 2009

function countBirths() {
var now = new Date().getTime();
var diff = (now - basisDate)/1000; // seconds
var births = (parseInt(diff * 3.94)); // 3.94 per second
births = births.toString();
births = addCommas(births);
msg = "The number of babies born in the world during 2009 up to this moment is estimated to be:- "
document.getElementById("babies").innerHTML = msg + births;

window.setTimeout("countBirths()",1000); // update each second

function addCommas(nStr) {
nStr = nStr.replace(/[^0-9\.]/g,"");
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1,$2');
return nStr;


Of course, the world population is not increasing at this rate!

"Money does not bring happiness, but it does enable you to be miserable in comfort". - Philip M's personal mantra

06-22-2009, 01:25 PM
Perfect - thanks for your help.
I realise that the population is not increasing at this rate, but the brief from my clients only includes births, not deaths!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum