
please help!
the counting days give me error<BR><BR>dim a <BR>a = countDays("08/09/2001","13/09/2001","11/09/2001;12/09/2001")<BR>a1 = countDays("31/08/2001","13/09/2001","11/09/2001;12/09/2001")<BR><BR>I am getting this error<BR>the a should give 2 but I am getting 3<BR>the a1 is give me 0 when I give different month<BR><BR><BR><BR>Function countDays(FromDate, ToDate, HoliDays) <BR>Dim FDate, TDate <BR>Dim Day1, Day2 <BR>Dim Month1, Month2 <BR>Dim Year1, Year2 <BR><BR>Dim tmpDate <BR>Dim i, j, k <BR><BR>countDays = 0 <BR>FDate = Split(FromDate, "/") <BR>TDate = Split(ToDate, "/") <BR><BR>Day1 = FDate(0) <BR>Month1 = FDate(1) <BR><BR>Year1 = FDate(2) <BR><BR>Day2 = TDate(0) <BR>Month2 = TDate(1) <BR>Year2 = TDate(2)<BR><BR>For k = Year1 To Year2 <BR> For j = Month1 To Month2<BR> For i = Day1 To Day2<BR> tmpDate = i&"/"&j&"/"&k<BR> If Weekday(tmpDate, vbMonday) <> 6 And Weekday(tmpDate, vbMonday) <> 7 Then <BR> if HolidayExist(i, j, k, HoliDays) = False Then<BR> countDays = countDays +1<BR> 'Response.Write (countDays)<BR> <BR> End If<BR> End If<BR> Next<BR> Next<BR> Next <BR>End Function<BR>Function HolidayExist(Day,Month, Year,HoliDays)<BR> Dim ArrHoliday<BR> Dim ArrDate<BR> Dim i<BR> HolidayExist = False<BR> ArrHoliday = Split(HoliDays, ";")<BR> 'for j=0 To UBound(ArrHoliday1)<BR> ' ArrHoliday = Split(ArrHoliday1(j), "")<BR> 'Response.Write ("Date<BR>"&ArrHoliday(1))<BR> For i = 0 To UBound(ArrHoliday)<BR> ArrDate = Split(ArrHoliday(i), "/")<BR> 'Response.Write (ArrDate(0))<BR> if CInt(ArrDate(0)) = CInt(Day) And CInt(ArrDate(1)) = CInt(Month) And CLng(ArrDate(2)) = CLng(Year) Then <BR> HolidayExist = True<BR> Exit Function<BR> End If <BR> 'Next<BR>Next<BR>End Function<BR><BR>

That will *NEVER* work!
Try it out BY HAND!<BR><BR>start date: 3/31/2001<BR>end date: 4/1/2001<BR><BR>no holidays<BR><BR>For k = 2001 To 2001 <BR> For j = 3 To 4<BR> For i = 31 To 1<BR><BR>No matter HOW many times the k and j loops would run, the i loop will NEVER EXECUTE.<BR><BR>You need to COMPLETELY THROW AWAY all of that code and start over.<BR><BR>Use DateTime values, instead of taking the strings apart. It makes a *LOT* more sense!<BR><BR>Something as simple as this:<BR><BR>fdate = CDate(FromDate)<BR>tdate = CDate(ToDate)<BR>While tdate < fdate<BR> ... check for holidays and weekends ...<BR> tdate = CDate( tdate + 1 )<BR>Wend<BR>

RE: That will *NEVER* work!
I try this code still I have problem with subract the holidays <BR><BR>holiday= ("Christmas27/12/2001,BoxinGday28/12/2001")'Request.QueryString("HD")<BR><BR>' ;to calculat how many week ends<BR>Function HowManyWD(FromDate,ToDate, WD)<BR> HowManyWD = DateDiff("ww", FromDate, ToDate, WD)  Int(WD = WeekDay(FromDate))<BR><BR>End Function<BR>'to find how many holidays fall into the date set<BR>Function HowManyHD(FromDate,ToDate,HD)<BR>Dim i<BR>Dim ArrHoliday<BR>Dim ArrDate<BR> ArrHoliday = Split(HD, ",")<BR> For i = 0 To UBound(ArrHoliday)<BR> ArrDate = Split(ArrHoliday(i), "")<BR> dim s<BR> s = ArrDate(1)<BR> Dim da<BR> da = DateValue(s)<BR> Response.Write (da)<BR> HowManyHD = DateDiff("d",FromDate,ToDate,da) Next<BR>EnD Function <BR>'to find how many work days<BR>Function HowManyWeekDay(FromDate, ToDate,holiday)<BR> Dim ToDateIsIncluded<BR> ToDateIsIncluded = true<BR> HowManyWeekDay = DateDiff("d", FromDate, ToDate) ToDateIsIncluded  HowManyWD(FromDate, ToDate, vbSunday)  HowManyWD(FromDate,ToDate, vbSaturday) 'HowManyHD(FromDate,Todate,holiday)<BR><BR>End Function<BR>dim days<BR>days = HowManyWeekDay (aLeaveStart, aLeaveEnd,holiday )<BR>Response.Write (days)

Okay, I give up...
...I'll write the code for you...<BR><BR><%<BR>' why not start off with an array? <BR>' instead of having to split to get it?<BR>holidays = Array("Christmas27/12/2001","BoxinGday28/12/2001")<BR>' create the master array of array of holiday info ONLY ONCE,<BR>' instead of every time you get to the function<BR>For h = 0 To UBound(holidays)<BR> holidays(h) = Split(holidays(h), "") <BR> holidays(h)(1) = CDate( holidays(h)(1) )<BR>Next<BR><BR>' *NOW* we define the function:<BR>'<BR>Function HowManyWeekDays( byVal fromDate, byVal toDate )<BR> Dim curdate, counter<BR> curDate = CDate(fromDate)<BR> toDate = CDate(fromDate)<BR> counter = 0<BR> While curDate < toDate<BR> If Not IsOffDay(curDate) Then counter = counter + 1<BR> curDate = CDate( curdate + 1 )<BR> Wend<BR> HowManyWeekDays = counter<BR>End Function<BR><BR>Function IsOffDay( dt )<BR> IsOffDay = True<BR> If Weekday(dt) = 1 OR Weekday(dt) = 7 Then Exit Function<BR> For hd = 0 TO UBound( holidays )<BR> If dt = holidays(hd)(1) Then Exit Function<BR> Next<BR> IsOffDay = False<BR>End Function<BR>%><BR><BR>I made the list of holidays a fixed array, instead of passing it to the function. SURELY you wouldn't use a different list of holidays for every request, would you? Don't all employees have the same holidays?<BR><BR>

Oops...a typo...
I decided to test the code. Found one error:<BR><BR>In the code:<BR> curDate = CDate(fromDate) <BR> toDate = CDate(fromDate) <BR> counter = 0 <BR><BR>The middle line is wrong. It should be:<BR> toDate = CDate(toDate) <BR><BR>Other than that, the code seemed to work. Sorry. Comes from typing off the top of my head instead of using an editor and testing.<BR><BR><BR><BR>

You're a better man then I <EOM>

Or more of a sucker?
Since I let him con me into writing the code?<BR><BR>Sigh. But he was *SO* lost. Did you see that code? Three different ways to do everything and none of them matching and...<BR><BR>I do have to wonder how people get into ASP with absolutely zero preparation. Well, not fair... I know a coupld of the stories: A friend is a graphic designer who was asked to learn ASP because his company couldn't afford a programmer. But you know, I think that they ended up spending twice what they would have if they'd hired a contractor...because it took him 4 times as long (at least) as the contractor would have taken. And even if he made half the salary...<BR><BR>But surely not *all* the tyros at ASP are in that same situation? So where is all the professional (or professorial, perhaps, or managerial) help they should be getting???<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

Forum Rules

