Status
Not open for further replies.

QRob001

Member
6
2010
0
0
I have the following java script for dispalying how long our gaming clan has been around. What it does is count downs the days until a sertain date, which is our Anniversary. What I would like to do is modify this code to update the year ("August 18, 2010") and restart the count and update the number of years or the Anniversary with out having to do it manually .

<SCRIPT LANGUAGE = "JavaScript">
var now = new Date();
// set this value to the countdown date.
var then = new Date("August 18, 2010");
var gap = then.getTime() - now.getTime();
gap = Math.floor(gap / (1000 * 60 * 60 * 24));
document.write(gap);
</SCRIPT>
<!--your message here-->day's Until 10th Anniversary
 
6 comments
check these links .. it might help
Code:
http://www.hashemian.com/tools/javascript-countdown.html

http://www.askdavetaylor.com/how_do_i_create_a_javascript_countdown_timer_on_my_web_page.html
 
I checked those 2 links im9ure but they were just creating a countdown timer like the one I have.

Yes Lock Down, I want it to update to the next year and begin the countdown. Just as if I had updated the year my self.

<SCRIPT LANGUAGE = "JavaScript">
var now = new Date();
// set this value to the countdown date.
var then = new Date("August 18, 2010");
var gap = then.getTime() - now.getTime();
gap = Math.floor(gap / (1000 * 60 * 60 * 24));
document.write(gap);
</SCRIPT>
<!--your message here-->day's Until 10th Anniversary

I would like the year date "2010" to updat to "2011" when the count down reaches "0". Then I would like it to update the year anniversary "10th" to "11th".
 
Last edited:
Try this:
Code:
<script type="text/javascript">
var now=new Date()

//Enter the Anniversary's MONTH (1-12) and DAY (1-31):
var then=new Date(now.getFullYear(), 8, 18)

var th = now.getFullYear() - 2000 // 11th anniversary on 2011

var monthtext=new Array("Jan","Feb","Mar","April","May","June","July","Aug","Sep","Oct","Nov","Dec")
then.setMonth(then.getMonth()-1) //change to 0-11 month format
var showdate="("+monthtext[then.getMonth()]+" "+then.getDate()+")" //show date of Anniversary

var one_day=1000*60*60*24
var calculatediff=""

calculatediff=Math.ceil((then.getTime()-now.getTime())/(one_day))
if (calculatediff<0){
var nextyearnow=new Date()
nextyearnow.setFullYear(now.getFullYear()+1)
calculatediff=Math.ceil((nextyearnow.getTime()-now.getTime())/(one_day)+calculatediff)
th += 1
}

var beforeAnniversaryText="day's Until " + th + "th Anniversary"
var onAnniversarytext="Today is Anniversary. Hooray :D"
//Display message accordingly
var pluraldayornot=(calculatediff==1)? "day" : "days"
if (calculatediff>0)
    document.write("<b>"+calculatediff+" "+pluraldayornot+" "+beforeAnniversaryText+" "+showdate+"!</b>")
else if (calculatediff==0)
    document.write("<b>"+onAnniversarytext+" "+showdate+"!</b>")

</script>
 
Status
Not open for further replies.
Back
Top