Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

holiday day count

Status
Not open for further replies.

ram567

Programmer
Dec 28, 2007
123
US
HI
the below code has monday to friday
i would like to add holiday code also
skip already given the below
could you help me where i have to add

'If today is Monday,then check Fridays data else check yesterday's data.
If strDayStamp="Mon" Then
strYesterdayDate=format(CVar(Date)-3, "mm/dd/yy") 'For weekend (Friday)
Else
strYesterdayDate=format(CVar(Date)-1, "mm/dd/yy") 'Date for previous day.
End If


Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
i = 1
strYesterdayDate

Else
Msgbox
Exit Sub
End If


Function PriorBusDay(sYear, dDate)
Dim HOL(9)
HOL(0) = DateValue("01-01-" & sYear) 'New Years
HOL(1) = DateValue("02-18-" & sYear) 'Familyday
HOL(2) = DateValue("03-21-" & sYear) 'Goodfriday
HOL(3) = DateValue("05-19-" & sYear) 'Victoriaday
HOL(4) = DateValue("07-01-" & sYear) 'Canadaday
HOL(5) = DateValue("08-04-" & sYear) 'Civic holiday

HOL(6) = DateValue("09-11-" & sYear) 'Labour day
HOL(7) = DateValue("10-13-" & sYear) 'Thanksgivingday
HOL(8) = DateValue("11-11-" & sYear) 'Rememberanceday
HOL(9) = DateValue("12-25-" & sYear) 'Christmasday
HOL(10) = DateValue("12-26-" & sYear) 'Boxing day

For i = 0 To 3
If WeekDay(HOL(i)) = 1 Then
HOL(i) = HOL(i) + 1
ElseIf WeekDay(HOL(i)) = 7 Then
HOL(i) = HOL(i) - 1
End If
Next

For i = 4 to 7
While WeekDay(HOL(i)) <> 2
HOL(i) = HOL(i) + 1
Wend
Next

While WeekDay(HOL(8)) <> 2
HOL(8) = HOL(8) - 1
Wend

While WeekDay(HOL(9)) <> 5
HOL(9) = HOL(9) + 1
Wend
HOL(9) = HOL(9) + 21

dDate = dDate - 1
DateChanged = True
Do While DateChanged
DateChanged = False
If WeekDay(dDate) = 1 Or WeekDay(dDate) = 7
dDate = dDate - 1
End If
For i = 0 To 10
If dDate = HOL(i) Then
dDate = dDate - 1
DateChange = True
End If
Next
Loop

PriorBusDay = dDate
End Function
 
Code:
strYesterdayDate = PriorBusDay(Year(Date()), DateValue(Date()))

Function PriorBusDay(sYear, dDate)
[red]  Dim HOL(10)[/red]
  HOL(0) = DateValue("01-01-" & sYear) 'New Years
  HOL(1) = DateValue("02-18-" & sYear) 'Familyday
  HOL(2) = DateValue("03-21-" & sYear) 'Goodfriday
  HOL(3) = DateValue("05-19-" & sYear) 'Victoriaday
  HOL(4) = DateValue("07-01-" & sYear) 'Canadaday
  HOL(5) = DateValue("08-04-" & sYear) 'Civic holiday

  HOL(6) = DateValue("09-11-" & sYear) 'Labour day
  HOL(7) = DateValue("10-13-" & sYear) 'Thanksgivingday
  HOL(8) = DateValue("11-11-" & sYear) 'Rememberanceday
  HOL(9) = DateValue("12-25-" & sYear) 'Christmasday
  HOL(10) = DateValue("12-26-" & sYear) 'Boxing day

  For i = 0 To 3
    If WeekDay(HOL(i)) = 1 Then
      HOL(i) = HOL(i) + 1
    ElseIf WeekDay(HOL(i)) = 7 Then
      HOL(i) = HOL(i) - 1
    End If
  Next

  For i = 4 to 7
    While WeekDay(HOL(i)) <> 2
      HOL(i) = HOL(i) + 1
    Wend
  Next

  While WeekDay(HOL(8)) <> 2
    HOL(8) = HOL(8) - 1
  Wend

  While WeekDay(HOL(9)) <> 5
    HOL(9) = HOL(9) + 1
  Wend
  HOL(9) = HOL(9) + 21

  dDate = dDate - 1
  DateChanged = True
  Do While DateChanged
    DateChanged = False
[red]    If WeekDay(dDate) = 1
      dDate = dDate - 2
    ElseIf WeekDay(dDate) = 7
      dDate = dDate - 1
    End If[/red]
    For i = 0 To 10
      If dDate = HOL(i) Then
        dDate = dDate - 1
        DateChange = True
      End If
    Next
  Loop

  PriorBusDay = dDate
End Function

You probably want to check how you're calculating the Holiday dates. For example, Christmas would be a January date. It looks like the code you're using for Christmas is similar to the code I used for Thanksgiving.
Code:
  HOL(9) = DateValue("12-25-" & sYear) 'Christmasday
  While WeekDay(HOL(9)) <> 5
    HOL(9) = HOL(9) + 1
  Wend
  HOL(9) = HOL(9) + 21
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top