# Day counter code

**URL:** <https://forum.kirupa.com/t/day-counter-code/247509>\
**Category:** Uncategorized\
**Created:** [December 24, 2007, 10:13pm UTC](https://forum.kirupa.com/t/day-counter-code/247509 "2007-12-24T22:13:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hellion](https://avatars.discourse-cdn.com/v4/letter/h/6a8cbe/32.png) [@Hellion](https://forum.kirupa.com/u/Hellion)\
**Post date:** [December 24, 2007, 10:13pm UTC](https://forum.kirupa.com/t/day-counter-code/247509/1 "2007-12-24T22:13:13Z")

</div>

I’m designing a site for my newborn baby girl and I would like to add a code that will show the following message: “It’s been 90 days since I was born”. Of course, the number would have to change each day. Where can I get a code that works like that.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![conreb](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@conreb](https://forum.kirupa.com/u/conreb)\
**Post date:** [May 14, 2008, 7:31pm UTC](https://forum.kirupa.com/t/day-counter-code/247509/2 "2008-05-14T19:31:51Z")

</div>

I have been trying to do the same for my first born baby. However, the calculation return 30 days of difference.

glosrfc, here is the code I am using… any help is greatly appreciated…

daysElapsedTextBox.variable = “elapsedDays”;  
var currentDatedate = new Date ();  
var birthDatedate = new Date (2008,8,2);  
var elapsedDate:Number = birthDate-currentDate;  
elapsedDays = Math.floor(elapsedDate/(1000_60_60\*24))

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [May 14, 2008, 10:12pm UTC](https://forum.kirupa.com/t/day-counter-code/247509/3 "2008-05-14T22:12:02Z")

</div>

Not sure what you’re trying to achieve with this line so delete it:  
daysElapsedTextBox.variable = “elapsedDays”;

This line is fine (I’m assuming that Datedate is the result of removing the colon after you’ve datatyped the variable):  
var currentDatedate = new Date ();

What date do you mean here? The date given is 2nd September 2008 which will return a negative number of days because it’s in the future. Do you mean 8th February (2008 ,1 ,2) or 8th March (2008, 2, 8)?  
var birthDatedate = new Date (2008,8,2);

Not sure why you’ve swapped these values around. The formula is designed to calcualte the number of days that have occurred since an event, not the number of days until it happens:  
var elapsedDate:Number = birthDate-currentDate;

This line is fine:  
elapsedDays = Math.floor(elapsedDate/(1000_60_60\*24))

You’re missing the line that takes the result of the calculation and displays it in the dynamic textfield:  
daysElapsedTextBox.text = “It’s been “+elapsedDays+” days since I was born”;

---

<div class="post-metadata">

**Author:** ![conreb](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@conreb](https://forum.kirupa.com/u/conreb)\
**Post date:** [May 15, 2008, 2:31pm UTC](https://forum.kirupa.com/t/day-counter-code/247509/4 "2008-05-15T14:31:30Z")

</div>

Sorry,  
Let me tell you what I am trying to do here. My daughter is due on Aug 2nd. I want to keep a day counter until due date. I basically took your code on this page and modified it a little bit.  
I am using AS3 so I have to declare variables.

daysElapsedTextBox.variable = “elapsedDays”;

basically, I am using a dynamic textbox called “daysElapsedTextBox” and then displaying value elapsedDays in there. So this is the line that takes the result of the calcuation and displays it. So I am not missing that line.

var elapsedDate:Number = birthDate-currentDate;  
I swaped the dates because I am using a future date (August 2nd, 200) and substract current date to give me days remaining.

I hope this makes sense.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [May 15, 2008, 5:46pm UTC](https://forum.kirupa.com/t/day-counter-code/247509/5 "2008-05-15T17:46:41Z")

</div>

[COLOR=“Red”]My daughter is due on Aug 2nd[/COLOR]  
That explains why the calculation is 30 days out - Flash returns month values in the range 0-11 and not 1-12. By setting the value of birthdate to new Date (2008,8,2) you’re telling Flash that you want to use 2nd September 2008.

[COLOR=“red”]daysElapsedTextBox.variable = “elapsedDays”;[/COLOR]  
I’m not familiar with AS3 (which is why this is the Flash 8 forum) but I don’t think you declare a variable to a textfield in that manner. In fact, I doubt that you even have to bother datatyping it as a Textfield if you’re going to draw it on the stage. Also, even if .variable worked, you’re not passing the number value of elapsedDays - you’re actually trying to pass a textual value of “elapsedDays”.

However, calculating the forthcoming event isn’t rocket science - here’s the code in AS2 which probably won’t need much, if any, modification to work in AS3:

```auto
var birthDate:Date = new Date(2008, 7, 26);
var currentDate:Date = new Date();
var differenceDate:Number = birthDate - currentDate;
var differenceDays:Number = Math.floor(differenceDate/(1000*60*60*24));
daysUntilTextBox.text = "Only another "+differenceDays+" days before I'm born";

```

---

<div class="post-metadata">

**Author:** ![conreb](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@conreb](https://forum.kirupa.com/u/conreb)\
**Post date:** [May 15, 2008, 7:04pm UTC](https://forum.kirupa.com/t/day-counter-code/247509/6 "2008-05-15T19:04:49Z")

</div>

Thank you so much GlosRFC. It worked. I did not know that flash returned months in 0-12. As you see I am a newbee and still trying to learn.

I really appreciate all your help.

Thank You
