Skip to main content
Participating Frequently
January 15, 2010
Question

Interest compounding starting at a certain date

  • January 15, 2010
  • 3 replies
  • 812 views

Hi folks,

I'm working on a small applet, and I was seeking a bit of guidance before I jumped in too deep into it.

In itself, it's pretty simple. I have an initial dollar figure, and it's growing by x every second. It started a few days ago, and I would like the Flash movie to keep up with it live, so when someone accesses that site, it shows the current amount.

I could use getTime, but it shows the actual time, not the time elapsed. And I could use the Date object or setDate, but I'm not sure if it would do any good, either.

I guess what I need is the amount of seconds that have elapsed since the original date. Once I have that, I think the interest-compounding might be easier.

Of course, this might all be crazy talk. Any help would be much appreciated!

Thanks in advance!

Napo

This topic has been closed for replies.

3 replies

Participating Frequently
January 15, 2010

Thanks guys! It makes pretty good sense.

The audience is mostly going to be in a specific timezone, so I don't think that would make a big difference. Otherwise, how would I grab it from a server in, say, Central Time?

I just found out that, fortunately, the dollar figure I need to add has already been compounded for interest and therefore the calculation wouldn't be too hard. It would just be initial figure + (number of seconds * figure per second) and it would stay like that for the duration of the app. No need to compound the daily interest every 24 hours or hourly or (eek!) every second. Whew.

Thanks again!

Napo

kglad
Community Expert
Community Expert
January 15, 2010

to use your server's clock you need to use server-side coding like php.

Participating Frequently
January 15, 2010

That's probably more than I would want to handle at this point. But thanks!

kglad
Community Expert
Community Expert
January 15, 2010

use:

var startDate:Date = new Date(2010,0,14);  // use your startyear, startmonth, startdate in the new Date() parameters.
var currentDate:Date = new Date();  // assuming user's clock is correct and in your timezone (which is pretty unlikely).  else use server date/time.
var numberOfSeconds:Number = (currentDate.getTime()-startDate.getTime())/1000;

January 15, 2010

To get the number of seconds since a date just make two date objects like startDate and nowDate and then subtract to get milliseconds and divide by 1000 to get seconds:

var startDate:Date = new Date(2010, 0, 5); //january 5th

var nowDate:Date = new Date();

trace((nowDate - startDate) / 1000);