<%
'******************************
'函數: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計算兩個時間內的工作日
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.