Countdown to my Birthday

Dear all,

I am developing a website that I hope to launch on my 30th Birthday, this is in a few weeks, on the homepage I would like to display a neat digital countdown to my birthday 12/05/2005. The site is going to be dedicated to life during my 30's so it is quite significant, also after I turn 30 it would be cool to display how long I have been in my 30's for. If you are interested the site is www.30somethinggamer.com, there is no content on the site at the moment at all it is just an empty shell, any advice would be most appreciated

Many thanks

Kevin
LVL 1
kevinsmith121Asked:
Who is Participating?
 
GwynforWebCommented:
Put  <div id="showTime"></div>  any where you want in the page to display the count down

<script>
birth=new Date("Dec 25 2005 00:00:01")

function showDiff(){
now=new Date()
diffTime=now.getTime()-birth.getTime()
if (diffTime > 0)
  msg="<p>Since my 30th birthday"
else{
  msg="<p>To my 30th birthday"
  diffTime=-diffTime
}

diff=new Date()
diff.setTime(diffTime+now.getTimezoneOffset( )*360*1000)
msg='<center><font size=5>'+(diff.getFullYear()-1970)+' years ' + diff.getMonth() + ' Months '+ diff.getDate()+' days ' + diff.getHours()+' hours '  + diff.getMinutes()+' minutes '+ diff.getSeconds()+' seconds' +msg+'</font></center>'

document.getElementById("showTime").innerHTML=msg

}
</script>


<body onload="showDiff();setInterval('showDiff()',1000)">
<div id="showTime"></div>
</body>
0
 
dfu23Commented:
0
 
YZlatCommented:
<script language="javascript">
<!--
var now = new Date();
var event = new Date("Dec 5 2005 00:00:01");
var seconds = (event - now) / 1000;
var minutes = seconds / 60;
var hours = minutes / 60;
var days = hours / 24;
ID=window.setTimeout("update();", 1000);
function update() {
now = new Date();
seconds = (event - now) / 1000;
seconds = Math.round(seconds);
minutes = seconds / 60;
minutes = Math.round(minutes);
hours = minutes / 60;
hours = Math.round(hours);
days = hours / 24;
days = Math.round(days);
document.write(days + " days, " + hours + " hours, " + minutes + " minutes, and " + seconds + " seconds until my Birthday!");
}
// -->
</script>
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
kevinsmith121Author Commented:
Thankyou all
0
 
kevinsmith121Author Commented:
This is an excellent set of answers with GwynforWeb's being the best, I have implimented, upped the points and awarded accordingly

many thanks

Kevin
0
 
GwynforWebCommented:
thx for the points, this is better. There is still a problem with daylight savings which I will look into.

<script>
birth=new Date("Apr 22 2005 00:00:01")

function showDiff(){
now=new Date()
diffTime=now.getTime()-birth.getTime()
if (diffTime > 0)
  msg="<p>Since my 30th birthday"
else{
  msg="<p>To my 30th birthday"
  diffTime=-diffTime
}

diff=new Date(diffTime+now.getTimezoneOffset( )*60*1000)

msg='<center><font size=5>'+(diff.getFullYear()-1970)+' years ' + diff.getMonth() + ' Months '+ (diff.getDate()-1)+' days ' + diff.getHours()+' hours '  + diff.getMinutes()+' minutes '+ diff.getSeconds()+' seconds' +msg+'</font></center>'
document.getElementById("showTime").innerHTML=msg

}
</script>


<body onload="showDiff();setInterval('showDiff()',1000)">
  <div id="showTime"></div>
</body>
</html>

0
 
GwynforWebCommented:
ah ha, I have got it exact at last, change to the birthday to hour 1

birth=new Date("Apr 22 2005 01:00:00")
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.