热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何计算VBScript中的最后一个工作日-HowtocalculatelastbusinessdayofmonthinVBScript

HowdoIcalculatethelastbusinessdayofmonthinVBScript?ItisforaReportingServicesreport

How do I calculate the last business day of month in Vbscript? It is for a Reporting Services report.

如何计算Vbscript中的最后一个工作日?它用于Reporting Services报告。

Thanks

4 个解决方案

#1


6  

How about:

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)

#2


2  

There is a good CodeProject article here: Working With Business Dates (Business Holidays/Weekends, etc).

这里有一篇很好的CodeProject文章:与商业日期(商务假期/周末等)合作。

This project is aimed at easing the troubles of figuring out valid business dates. It includes a few functions I have created to determine whether or not the date is a holiday or a weekend, and also to retrieve either the next or last business day. There is also a function to find the last day of a given month.

该项目旨在缓解确定有效营业日期的麻烦。它包括我创建的一些函数,用于确定日期是假日还是周末,还可以检索下一个或最后一个工作日。还有一个功能可以找到给定月份的最后一天。

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.: You'll find the functions LastDayOfMonth and isHoliday in the article.

P.S。:你会在文章中找到函数LastDayOfMonth和isHoliday。

#3


1  

Here is one solution for anyone who is looking to get Last business day of the previous month.

对于希望获得上个月最后一个工作日的人来说,这是一个解决方案。

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

#4


0  

If you mean the last week day of the month (M-F), then try:

如果您指的是该月的最后一周(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

推荐阅读
author-avatar
本多天舞
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有