need help

Results 1 to 2 of 2

Thread: need help

  1. #1
    Join Date
    Dec 1969

    Default need help

    I am calculating the total days between two set of date range<BR>- Need to subtract the weekend<BR>- Need to subtract this holidays <BR>labour day (first Monday of September), thanks giving Christmas(Dec 25), boxing day(Dec 26),new year(Jan 1) good Friday <BR>victoria day (third week of Monday of May) Canada day(July 1) civic holiday(it comes every first Monday of Aug)<BR>but I accomplished some holidays but not all of them<BR>Here is my code any one can help me because I having trouble get <BR>some holidays<BR><BR>// Get the milliseconds for this Date object. <BR>var bufferA = Date.parse (aLeaveStart);<BR>var bufferB = Date.parse (aLeaveEnd);<BR><BR><BR>var number = (bufferB+86400000) - bufferA;<BR> iOut = parseInt(number/86400000);<BR><BR> var dtTemp;<BR><BR>var i=0,k=0,d = 0,j=0;ju=0;<BR> <BR>while(i&#060;iOut){<BR>num = i*86400000;<BR>var nDays;<BR>var tot = (bufferA+num);<BR>dtTemp = new Date( tot )<BR><BR>var holMonth = dtTemp.getMonth();<BR>var holDate = dtTemp.getDate();<BR>var lngWeekDay = dtTemp.getDay();<BR>//to deduct the christmas and boxing holidays from the request date range<BR>if (holMonth == 11){<BR> <BR> if ((holDate == 25) &#124&#124( holDate == 26) ){<BR> d=d+1;<BR><BR> }<BR>}<BR>//to deduct the January first from the request date range<BR>if (holMonth == 0){<BR> if ((holDate == 1)){<BR> j=j+1; <BR> <BR> }<BR>}<BR>//to deduct the canaday day from the request range date<BR>if (holMonth == 6){<BR> if (holDate == 1){<BR> ju=ju+1; <BR> <BR> }<BR>}<BR><BR>// to deduct the week end from the request range date<BR>if ((lngWeekDay == 6) &#124&#124 (lngWeekDay == 0)){ <BR> k=k+1;<BR> }<BR> <BR> i=i+1;<BR><BR>}<BR><BR>if ((<BR>var lngVacDays=(iOut-k-ju-j-d);<BR><BR> Response.Write (lngVacDays);<BR>

  2. #2
    Join Date
    Dec 1969

    Default Your code is too simplistic...

    What happens if one of those holidays falls on a weekend day???<BR><BR>Sure, you&#039;ll subtract both the weekend day *and* the holiday. But is that the RIGHT answer?<BR><BR>Suppose, for example, somebody wants the number of working days from December 21st to December 24th. But if Christmas falls on a Saturday, then December 24th is a holiday! But your code won&#039;t figure that out and will give an answer that is one day too big!<BR><BR>Really, the best way to do this is simply build a fixed calendar of holidays, by year. Then index into the proper year and then check to see if the date is marked as a holiday.<BR><BR>holidays = new Array(<BR>&nbsp; &nbsp; new Array( 2001, 1.01, 7.03, 12.25, 12.26, ... ),<BR>&nbsp; &nbsp; new Array( 2002, 1.01, ..., 12.25, 12.26, ... ),<BR>&nbsp; &nbsp; new Array( 2003, 1.01, ..., 12.24, 12.25, ... ),<BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; );<BR><BR>*SURELY* you don&#039;t need more than 5 or 10 years&#039; worth of holidays? So the fixed table would be much easier to do.<BR><BR>Incidentally, if you care, this would be *TONS* easier to do in VBScript, which has much more useful functions for working with dates.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts