I have a webpage with a basic js script that counts the days since my son was born and displays the number on my page. The script works as described quite well. One thing I would like to do is break the number down into years and days rather than just the number of days. I'm not a very well-versed coder and the script is something I got out of a js book and modified. The code and page implementation is outlined below. If anyone could help me modify the script so I can show years and days I would be very appreciative.
Script:
Here is how it is displayed on the web page:
I'd like to have "He is now 'x' years and 'y' days old"
I tried creating a variables "years" and "days" and performing:
years = daysTill(birthday)/365
days = daysTill(birthday)%365
but these did not work.
Suggestions?
Script:
Code:
////////////////////
//Countdown Script//
////////////////////
now = new Date
thisYr = now.getYear()
if (thisYr<1900)
{
thisYr = thisYr+1900
}
nextYr = thisYr+1
lastYr = thisYr-1
birthday = new Date(2001,0,20)
function dayToDays(inTime)
{
return (Math.floor(inTime.getTime() / (1000*60*60*24)))
}
function daysTill(inDate)
{
return dayToDays(now) - dayToDays(inDate)
}
Here is how it is displayed on the web page:
Code:
<script language=javascript type="text/javascript">
<!--Hide script from old browsers
document.write("He is now <font color=red size=5>"+daysTill(birthday)+"</font><font face=\"Arial, Helvetica,sans-serif\" size=5> days old!</font>")
//End hide script -->
</script>
I'd like to have "He is now 'x' years and 'y' days old"
I tried creating a variables "years" and "days" and performing:
years = daysTill(birthday)/365
days = daysTill(birthday)%365
but these did not work.
Suggestions?