在VB中,计算每月的第5个工作日 [英] In VB, calculating the 5th working day of every month
问题描述
在VB中,我可以使用什么编码来计算每月的第5个工作日?而且如果第五天是放假一天的假期.
In VB, what coding could I use to calculate the 5th working day of every month? And if the 5th day is a holiday to go up one day.
推荐答案
您需要一个与之比较的假期日期列表.您将需要分别构建和存储该列表.您没有说过VB的哪个变体(VBA?VB.NET?),但是在VB.NET中,您可以这样做:
You would need a list of holiday dates with which to compare. You would need to build and store that list separately. You did not say what variant of VB (VBA? VB.NET?) but in VB.NET you could do:
Dim datevalue As DateTime = New DateTime(DateTime.Year, DateTime.Month, 1)
Dim dayIsFound As Boolean = False
Dim workDays As Integer
workDays = 1
While Not dayIsFound
If ( dateValue.DayOfWeek <> DayOfWeek.Saturday _
And dateValue.DayOfWeek <> DayOfWeek.Sunday _
And Not HolidayList.Contains( dateValue ) _
workDays = workDays + 1
End If
If index >= 5 Then
dayIsFound = True
Else
dateValue = dateValue.AddDays(1)
End If
End While
从技术上讲,可以建立一种算法来根据联邦准则(在美国)来确定主要假期,但是它很复杂,并且可能与您要为其建立此组件的公司的假期不符.
Technically, it is possible to build an algorithm that determines the major holidays based on Federal guidelines (in the US) but it is complicated and may not conform to the holidays of the company to whom you are building this component.
这篇关于在VB中,计算每月的第5个工作日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!