Thanks Anthony!
_____ From: Anthony Humphreys [mailto:[email protected]] Sent: Wednesday, July 18, 2012 3:20 PM To: [email protected] Cc: WebDude Subject: Re: TeraScript-Talk: date calculations I have fixed and tested the businessDaysBetweenDates(jd1,jd2) javascript function In the attached zip file is the function (and the dependencies required) to test the function in an HTML page. You may 'play' with the file for yourself to deem how suitable it is for your purposes. NOTE: This function does NOT account for any types of holidays occurring between the dates Here's the function: function businessDaysBetweenDates (jd1, jd2) { var StartDay; var EndDay; var StartWeek; var EndWeek; var wks; var BusinessDays; // Correct jd to only date part jd1 = JD_date_part(jd1); jd2 = JD_date_part(jd2); // assign smaller day to StartDay // assign larger day to EndDay if (jd1 < jd2) { var StartDay = jd1; EndDay = jd2; } else { StartDay = jd2; EndDay = jd1; } // Are the start and end days on the Same day or in the same weekend? if (StartDay == EndDay) { // is weekend ? if (day_of_week_index_JD0(StartDay) === 0 || day_of_week_index_JD0(StartDay) == 6) { return (0); // same day on weekend - no business days } else { return (1); // same day - one business day (inclusive) } // sat and sun of same weekend } else if ( ((StartDay + 1) == EndDay) && (day_of_week_index_JD0(StartDay) == 6) ) { return (0); // start and end on same weekend - no business days } // correct for startDay on Weekend by // moving startDay to following Monday if (day_of_week_index_JD0(StartDay) == 6) { StartDay = StartDay + 2; } else if (day_of_week_index_JD0(StartDay) === 0) { StartDay = StartDay + 1; } // correct for EndDay on weekend by // moving endDay to previous Friday if (day_of_week_index_JD0(EndDay) === 0) { EndDay = EndDay - 2; } else if (day_of_week_index_JD0(EndDay) == 6) { EndDay = EndDay - 2; } // Get WeekNumbers for StartDay and EndDay StartWeek = (StartDay / 7); StartWeek = Math.trunc(StartWeek); EndWeek = (EndDay / 7); EndWeek = Math.trunc(EndWeek); //calc Difference in weeks wks = EndWeek - StartWeek; // different means of doing calculations // depending on the difference // in the number of weeks if (wks === 0) { BusinessDays = day_of_week_index_JD0(EndDay) - day_of_week_index_JD0(StartDay) + 1; // add 1 because business days are _inclusive_ } else { BusinessDays = (6 - day_of_week_index_JD0(StartDay)) + day_of_week_index_JD0(EndDay) + (5 * (wks -1)); // number of business days left in Start week // plus number of business days in End week // plus 5 days for every week between } // All Done; now return BusinessDays return (BusinessDays); } On Mon, Jul 16, 2012 at 8:00 AM, WebDude <[email protected]> wrote: Actually, I am looking for something like this... BusinessTimeBetweenDates(D1,D2) John Muldoon Corporate Incentives 3416 Nicollet Ave S Minneapolis, MN 55408-4552 612.822.2222 [email protected] <http://cipromo.com/> http://cipromo.com _____ From: Anthony Humphreys [mailto:[email protected]] Sent: Saturday, July 14, 2012 2:18 PM To: [email protected] Subject: Re: TeraScript-Talk: date calculations WebDude, Are you looking for a function like this? BusinessDaysBetweenDates(D1,D2) On Sat, Jul 14, 2012 at 2:24 PM, WebDude <[email protected]> wrote: I have 2 timestamps in the db, we can call them starttime and endtime for now. Has anyone ever wrote a down and dirty calculation that doesn't include weekend days (i.e saturady and sunday? Holidays? I would settle for just a weekend day omit for now. I have been farting around with this and ended up with a bunch of code, but I was hoping for something more elegant. In other words, I am trying to return the total time between the 2 dates and the average time between the two dates for the total return. I started by writing direct db actions to the db but it is pretty daunting for me. Going from datetosecs is relatively easy to figuring this out. Trying to omit Saturaday and Sunday gets a bit more complex, especially if you are dealing with hundreds of returns. Witango 2000 for now... no Robert, I don't have the new servers up and running yet. Hopefully soon! ;-) WebDude _____ To unsubscribe from this list, please send an email to [email protected] with "unsubscribe terascript-talk" in the body. _____ To unsubscribe from this list, please send an email to [email protected] with "unsubscribe terascript-talk" in the body. ---------------------------------------- To unsubscribe from this list, please send an email to [email protected] with "unsubscribe terascript-talk" in the body.
<<att28ad.gif>>
