Day counter code

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.

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/(10006060*24))

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/(10006060*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”;

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.

[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:

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";

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