# flash8/Actionscript2.0 A Countdown Coding Issue w/setting target date to New Years

**URL:** <https://forum.kirupa.com/t/flash8-actionscript2-0-a-countdown-coding-issue-w-setting-target-date-to-new-years/317265>\
**Category:** flash\
**Created:** [December 15, 2010, 11:11am UTC](https://forum.kirupa.com/t/flash8-actionscript2-0-a-countdown-coding-issue-w-setting-target-date-to-new-years/317265 "2010-12-15T11:11:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Starrey](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Starrey](https://forum.kirupa.com/u/Starrey)\
**Post date:** [December 15, 2010, 11:11am UTC](https://forum.kirupa.com/t/flash8-actionscript2-0-a-countdown-coding-issue-w-setting-target-date-to-new-years/317265/1 "2010-12-15T11:11:30Z")

</div>

The following is the code i used for xmas countdown worked fine.I adapted it for a New Years countdown and its not working.Thankfully project is almost done and have time to learn a LOT more about actionscripting. Appreciate anyone can help here:

//onEnterFrame allows for a function to be called every tick  
this.onEnterFrame = function() {  
//Stores the current date  
var today:Date = new Date();  
//Stores the Current Year  
var currentYear = today.getFullYear();  
var currentNewYear = today.getFullYear()+1; \<\<\<\<here is what i added to try to get the target date into the new year,would like it to work year after year but did try just putting 2011 into the target date that didnt work either\>\>\>\>\>\>\>\>\>\>\>\>\>\>  
//Stores the Current Time  
var currentTime = today.getTime();  
//Creates and stores the target date  
var targetDate:Date = new Date(currentNewYear,12,1); \<\<\<\<where i added that change\>\>\>\>\>  
var targetTime = targetDate.getTime();  
//Determines how much time is left. Note: Leaves time in milliseconds  
var timeLeft = targetTime - currentTime;  
if (timeLeft \<= 0) {  
this.onEnterFrame = null;  
gotoAndPlay(2);

```
}

```

var sec = Math.floor(timeLeft/1000);  
var min = Math.floor(sec/60);  
var hours = Math.floor(min/60);  
var days = Math.floor(hours/24);  
//Takes results of var remaining value. Also converts “sec” into a string  
sec = String(sec % 60);  
//Once a string, you can check the values length and see whether it has been reduced below 2.  
//If so, add a “0” for visual purposes.  
if(sec.length \< 2){  
sec = “0” + sec;  
}  
min = String(min % 60);  
if(min.length \< 2){  
min = “0” + min;  
}  
hours = String(hours % 24);  
if(hours.length \< 2){  
hours = “0” + hours;  
}  
days = String(days);  
//Joins all values into one string value  
var counter:String = days + “:” + hours + “:” + min + “:” + sec;  
time2\_txt.text = counter;  
}
