<%
'******************************
'函数: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
%>
asp计算两个时间内的工作日
最新推荐文章于 2022-03-12 16:42:53 发布