Solved

# Countdown to my Birthday

Posted on 2005-04-20
Medium Priority
426 Views
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
0
Question by:kevinsmith121

LVL 14

Assisted Solution

dfu23 earned 200 total points
ID: 13827090
0

LVL 35

Assisted Solution

YZlat earned 600 total points
ID: 13827373
<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

LVL 31

Accepted Solution

GwynforWeb earned 1200 total points
ID: 13829481
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>

<div id="showTime"></div>
</body>
0

LVL 1

Author Comment

ID: 13834722
Thankyou all
0

LVL 1

Author Comment

ID: 13834767
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

LVL 31

Expert Comment

ID: 13836084
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>

<div id="showTime"></div>
</body>
</html>

0

LVL 31

Expert Comment

ID: 13839505
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
###### Suggested Courses
Course of the Month9 days, 22 hours left to enroll