如何计算VBScript中的最后一个工作日?它适用于Reporting Services报告。
由于
答案 0 :(得分:7)
怎么样:
intMonth=11
'Use zero to return last day of previous month '
LastDayOfMonth= dateserial(2008,intMonth+1,0)
'Saturday '
If WeekDay(LastDayOfMonth,1)=7 Then LastDayOfMonth=LastDayOfMonth-1
'Sunday '
If WeekDay(LastDayOfMonth,1)=1 Then LastDayOfMonth=LastDayOfMonth-2
Msgbox LastDayOfMonth & " " & Weekdayname(Weekday(LastDayOfMonth,1),1)
答案 1 :(得分:2)
这里有一篇很好的CodeProject文章:Working With Business Dates (Business Holidays/Weekends, etc)。
该项目旨在简化 找出有效的麻烦 营业日期。它包括一些 我创建的函数来确定 是否日期是假日 或者周末,还要检索 无论是下一个还是最后一个工作日。 还有一个功能可以找到 某个月的最后一天。
Function LastBusinessDay(sDate)
Dim iDay, iDaysToAdd, iDate
iDaysToAdd = 0
iDate = sDate
x = 1
Do while iDaysToAdd >= 0
If Weekday(iDate) = 1 or Weekday(iDate) = 7 or _
isHoliday(iDate) <> 0 then
iDay = Weekday(iDate)
Select Case cint(iDay)
Case 1 'Sunday
iDate = DateAdd("d", -1, iDate)
Case 7 'Saturday
iDate = DateAdd("d", -1, iDate)
Case else 'this is a valid day
if isHoliday(iDate) > 0 then
iDate = dateadd("d", -(isHoliday(iDate)), iDate)
else
iDaysToAdd = iDaysToAdd - 1
end if
End Select
end if
Loop
LastBusinessDay = iDate
End Function
P.S。:您可以在文章中找到函数LastDayOfMonth
和isHoliday
。
答案 2 :(得分:1)
对于希望获得上个月最后一个工作日的人来说,这是一个解决方案。
Dim lastbusinessdayofprevmonth
Sub GetLastDay()
Dim curdate
curdate = Date()
Dim firstdayofcurmonth
firstdayofcurmonth = Month(curdate) & "/1/" & Year(curdate)
Dim lastdayofprevmonth
lastdayofprevmonth = DateAdd("d", -1, firstdayofcurmonth)
Dim day
day = weekday(lastdayofprevmonth)
if(day = 1) then
lastbusinessdayofprevmonth = DateAdd("d", -2, lastdayofprevmonth)
elseif (day = 7) then
lastbusinessdayofprevmonth = DateAdd("d", -1, lastdayofprevmonth)
else
lastbusinessdayofprevmonth = lastdayofprevmonth
end if
end sub
答案 3 :(得分:0)
如果您指的是该月的最后周日(M-F),请尝试:
Dim d
d = DateAdd("m", 1, Now)
d = Month(d) & "/1/" & Year(d)
d = DateAdd("d", -1, d)
If Weekday(d) = 7 Then
d = DateAdd("d", -1, d)
ElseIf Weekday(d) = 1 Then
d = DateAdd("d", -2, d)
End If
MsgBox d