asp计算两个时间内的工作日

<%
'******************************
'函数:workdays(date_begin , date_end)
'参数:date_begin,开始日期;date_end,结束日期AddArray,特定假日数组;自定义工作日数组SArray,
'日期:2007/11/16
'描述:计算两个时间内的工作日
'作者:小蔡哥
'示例:workdays("2007-05-18" , "2007-05-21");DateSub.txt=2007-11-16,2007-11-17
'******************************
function workdays(date_begin , date_end)
 date_begin = CDate(date_begin)
 date_end = CDate(date_end)
 
 '特定假日、工作日数组
 set fso=server.CreateObject("Scripting.FileSystemObject")
 Set txtFiles=fso.OpenTextFile(Server.MapPath("DateSub.txt"))
 While Not txtFiles.AtEndOfStream
    SArray = Split(txtFiles.ReadLine,",")
 Wend
 txtFiles.Close
 
 set fso=server.CreateObject("Scripting.FileSystemObject")
 Set txtFilea=fso.OpenTextFile(Server.MapPath("DateAdd.txt"))
 While Not txtFilea.AtEndOfStream
    AddArray = Split(txtFilea.ReadLine,",")
 Wend
 txtFilea.Close
 
 
 '数组长度
 'response.Write(UBound(MyArray)+1)
 if IsDate(date_begin) and IsDate(date_end) then
   Sumdays = 0
   '判断是否是星期天,如果是星期六、星期天,如果是则workdays逐一加1
   for d=0 to datediff("d" , date_begin , date_end)
   if weekday(date_begin + d) <> 1 and weekday(date_begin + d) <> 7 then
   Sumdays = Sumdays + 1
   end if
   next
  
   '减去自定义假日:判断特定假日是否在计算范围内,如果在则workdays逐一减1,日期不能为双休,否则会减错
   for i_loop=0 to UBound(SArray)
   if CDate(SArray(i_loop))>=date_begin and CDate(SArray(i_loop))<=date_end and weekday(CDate(SArray(i_loop)) + d) <> 1 and weekday(CDate(SArray(i_loop)) + d) <> 7 then
      Sumdays = Sumdays - 1
   end if
   next
  
   '加上自定义工作日:判断自定义工作日是否在计算范围内,如果在则workdays逐一加1,日期必须是双休,否则会加错
   for j_loop=0 to UBound(AddArray)
   if CDate(AddArray(j_loop))>=date_begin and CDate(AddArray(j_loop))<=date_end then
      Sumdays = Sumdays + 1
   end if
   next
     
   workdays=Sumdays
 else 
   workdays = "未知"
 end if
 
end function
%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值