scdgoofy

06-04-2003, 09:18 PM

Hey there... newbie here needing help with an age script.

I modified a script to show my newborn son's age in days, weeks and months. The modification is ugly, but it works. (Note that the "year" calculation is actually divided by 52 to get me weeks.)

However, it is pulling the time from my host's server, located in Hong Kong. I'd like to make it reflective of Pacific Time so that the days and weeks are more accurate.

If I've done my math right, I'm looking at adding a -15 hour offset. However, I don't know where to put it in the script, nor do I know if I need to do it in milliseconds or not.

(And if I wanted to get really crazy, it would be cool to put in an offeset that would reflect his actual time of birth (10:08 a.m.), which, if my math is right, would be a +10 hour offset from midnight of any given day.)

Any help would be great. Thanks!

<script>

/*

Ultimate Age calculator script- By JavaScript Kit (http://www.javascriptkit.com)

Over 200+ free scripts here!

Credit must stay intact for use

*/

var one_day=1000*60*60*24

var one_month=1000*60*60*24*30

var one_year=1000*60*60*24*30*12/52

function displayage(yr, mon, day, unit, decimal, round){

today=new Date()

var pastdate=new Date(yr, mon-1, day)

var countunit=unit

var decimals=decimal

var rounding=round

finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year

decimals=(decimals<=0)? 1 : decimals*10

if (rounding=="rounddown")

document.write(Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)

else

document.write(Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)

}

//Sample usage

//displayage (year, month, day, unit, decimals, rounding)

//Unit can be "years", "months", or "days"

//Decimals specifies demical places to round to (ie: 2)

//Rounding can be "roundup" or "rounddown"

//displayage(2002, 12, 13, "years", 0, "rounddown")

</script>

Tyler's age today:</b></font><p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> <font face="Arial"> <br><b>

<script>

displayage(2002, 12, 13, "days", 0, "rounddown")

</script>

</b> or <br>

<b>

<script>

displayage(2002, 12, 13, "weeks", 0, "rounddown")

</script>

</b> or <br>

<b>

<script>

displayage(2002, 12, 13, "months", 1, "rounddown")

</script>

</b>

I modified a script to show my newborn son's age in days, weeks and months. The modification is ugly, but it works. (Note that the "year" calculation is actually divided by 52 to get me weeks.)

However, it is pulling the time from my host's server, located in Hong Kong. I'd like to make it reflective of Pacific Time so that the days and weeks are more accurate.

If I've done my math right, I'm looking at adding a -15 hour offset. However, I don't know where to put it in the script, nor do I know if I need to do it in milliseconds or not.

(And if I wanted to get really crazy, it would be cool to put in an offeset that would reflect his actual time of birth (10:08 a.m.), which, if my math is right, would be a +10 hour offset from midnight of any given day.)

Any help would be great. Thanks!

<script>

/*

Ultimate Age calculator script- By JavaScript Kit (http://www.javascriptkit.com)

Over 200+ free scripts here!

Credit must stay intact for use

*/

var one_day=1000*60*60*24

var one_month=1000*60*60*24*30

var one_year=1000*60*60*24*30*12/52

function displayage(yr, mon, day, unit, decimal, round){

today=new Date()

var pastdate=new Date(yr, mon-1, day)

var countunit=unit

var decimals=decimal

var rounding=round

finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year

decimals=(decimals<=0)? 1 : decimals*10

if (rounding=="rounddown")

document.write(Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)

else

document.write(Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)

}

//Sample usage

//displayage (year, month, day, unit, decimals, rounding)

//Unit can be "years", "months", or "days"

//Decimals specifies demical places to round to (ie: 2)

//Rounding can be "roundup" or "rounddown"

//displayage(2002, 12, 13, "years", 0, "rounddown")

</script>

Tyler's age today:</b></font><p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> <font face="Arial"> <br><b>

<script>

displayage(2002, 12, 13, "days", 0, "rounddown")

</script>

</b> or <br>

<b>

<script>

displayage(2002, 12, 13, "weeks", 0, "rounddown")

</script>

</b> or <br>

<b>

<script>

displayage(2002, 12, 13, "months", 1, "rounddown")

</script>

</b>