0
웹 양식에서 주말 및 공휴일 제외 일 수를 계산하려고합니다. 휴일 날짜가 날짜 형식 (yyyy-MM-dd) 인 SQL 데이터베이스가 있습니다. 사용자는 MM/dd/yyyy 형식을 사용하여 날짜를 추가합니다. 내 코드 작업의 주말 부분은 계산하지 않습니다. 날짜가 공휴일인지 아닌지 파악하면 계산되지 않고 작동하지 않습니다. 여기 내 코드가있다. 나는 밖으로 주목 된 모든 것을 시도했다. 입력 한 날짜와 SQL 날짜를 비교하는 방법을 알아내는 데 도움을 주셔서 감사합니다.날짜 비교 - 날짜 형식 문제
Dim intCount As Integer
Dim temp As Integer
'Set same day as 1 <-- your preference. Though you can't work out averages if they are 0.
'Im not checking if this day is a holiday (though in theory you shouldn't have to!).
If StartDate = EndDate Then
WorkingDays = 1 'Change me to your needs.
Exit Function
End If
intCount = 0 ' Now we start counting days. 'If you always want to count the first day, set this to 1.
Do Until StartDate = EndDate
'First, we find out if this day is a weekday or a weekend.
'If weekday, 1 gets added to the number of days.
Select Case Weekday(StartDate)
Case Is = 1, 7
intCount = intCount 'Weekend, so nothing added.
Case Else
intCount = intCount + 1
End Select
'Now, if this day was a holiday, we take it back off again!
'Dim vsqldate = DateTime.ParseExact(StartDate, "yyyy-MM-dd", Nothing)
'Dim vsqldate = StartDate.ToString("yyyy-MM-dd")
'Dim vsqldate = fromDt.ToString("yyyy-MM-dd")
Dim vsqldate = CDate(Format(StartDate, "yyyy-MM-dd"))
Dim strWhere = "Holiday= #" & vsqldate & "#" 'change fieldname.
If (DCount("Holiday", "tblCodesholidays", strWhere) > 0) Then 'Change to your field/table names.
intCount = intCount - 1
End If
StartDate = StartDate.AddDays(1) 'We move to the next day.
Loop
WorkingDays = intCount
vsqldate는 어떻게 정의합니까? 위에서 시도한 방법 중 어느 것도 작동하지 않았습니다. 감사! – user3033348
아마도 귀하의 질문에 대한 오해가있었습니다. vsqldate는 최종 사용자가 양식에 입력 한 날짜입니까? – DMason
StartDate는 양식의 필드 이름입니다. StartDate에 대한 변수를 정의하여 SQL 테이블 tblCodesholidays의 날짜 필드 Holiday와 비교할 수있었습니다. StartDate = Holiday (테이블의 날짜) 인 경우 계산하지 않으려 고합니다. 참고 - StartDate와 마찬가지로 vsqldate를 정의하려고 시도했지만 작동하지 않았습니다. 도와 주셔서 감사합니다! – user3033348