Increment day based on start date with AS {resolved}

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

I need to add to my company website a display of "number of days without a lost time accident". This is based on a "start" date and then obviously increments each day. I'll also need to display this on a printer friendly html page so I'll need either a javascript or php version as well. I think I could probably handle the php deal, but I'm not very good with javascript or actionscript and could use some help. I did find the following action script which appears to be close to what I want, but I could tell by looking at it, it's not going to increment properly. We're based on a 7 day work week, not five. And if I'm reading the script right if the page gets refreshed or somebody new looks at it "int" gets reset to 0. I'm also not sure how to actually use the result numberOfDays and make it display that on the flash page. I assume make a dynamic text box and assign it the same name as numberOfDays ?

Here's the script I'm looking at.
http://rmaxim.blogspot.com/2007/05/calc ... -with.html




Code: [ Select ]
public static const millisecondsPerDay:int = 1000 * 60 * 60 * 24;

public function businessDaysElapsed(date1:Date,date2:Date):int {
var numberOfDays:int = 0;

while (date1 < date2) {
//increment date by a day
date1.setTime(date1.getTime() + millisecondsPerDay);
//if day is between monday and friday, add one day
if (date1.day >= 1 && date1.day <=5) {
numberOfDays ++
}
}
return numberOfDays;
}
  1. public static const millisecondsPerDay:int = 1000 * 60 * 60 * 24;
  2. public function businessDaysElapsed(date1:Date,date2:Date):int {
  3. var numberOfDays:int = 0;
  4. while (date1 < date2) {
  5. //increment date by a day
  6. date1.setTime(date1.getTime() + millisecondsPerDay);
  7. //if day is between monday and friday, add one day
  8. if (date1.day >= 1 && date1.day <=5) {
  9. numberOfDays ++
  10. }
  11. }
  12. return numberOfDays;
  13. }


Any help would be appreciated. I really need to get this on the website before the end of the year.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Found a script to do what I need.

Code: [ Select ]
oldDate = new Date(2005,2,6); // february 6 2005

newDate = new Date();     // today

elapsed = newDate - oldDate;  // elapsed milliseconds


// to put it in a text box:

daysElapsedTextBox.text = Math.floor(elapsed/(1000*60*60*24)) + " days without a lost time accident. ";
  1. oldDate = new Date(2005,2,6); // february 6 2005
  2. newDate = new Date();     // today
  3. elapsed = newDate - oldDate;  // elapsed milliseconds
  4. // to put it in a text box:
  5. daysElapsedTextBox.text = Math.floor(elapsed/(1000*60*60*24)) + " days without a lost time accident. ";

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 19 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.