日期之间的经典 ASP 工作日数 [英] Classic ASP number of weekdays between dates
本文介绍了日期之间的经典 ASP 工作日数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Classic ASP VBScript 中是否有任何方法可以获取两个日期之间的工作日数?显然,我们有 DateDiff()
函数,但这会拉回总天数,但我想省略周末.
Is there any way in Classic ASP VBScript to get the number of weekdays between 2 dates? Obviously, we have the DateDiff()
function but this will pull back the total number of days but I would like to omit the weekends.
推荐答案
VBScript 不包含请求的操作,但作为 DateDiff
与 ww
间隔返回的数量两个日期之间的星期日,确保开始和结束日期不在周末我们可以直接计算工作日数:
VBScript does not include the requested operation, but as DateDiff
with a ww
interval returns the number of Sundays between two dates, ensuring that start and end dates are out of the weekend we can directly calculate the number of working days:
Option Explicit
Function WorkingDaysBetween( ByVal d1, ByVal d2 )
Dim d
' Adjust date order to simplify calcs and always return 0 or positive number
If d1 > d2 Then
d = d1 : d1 = d2 : d2 = d
End If
' Move start date forward if it is a weekend
d = WeekDay( d1, vbMonday )
If d > 5 Then d1 = DateAdd( "d", 3-(d6 + d7), d1)
' Move end date backward if it is a weekend
d = WeekDay( d2, vbMonday )
If d > 5 Then d2 = DateAdd( "d", -1*(d6 + d7), d2)
' Calculate
' DateDiff("d") = Number of days between dates
' +1 to include start day
' -2 * DateDiff("ww") to exclude weekends between dates
WorkingDaysBetween = 1 + DateDiff("d", d1, d2, vbMonday) - 2*DateDiff("ww", d1, d2, vbMonday)
' If the result is negative, there are no working days between both dates
If WorkingDaysBetween < 0 Then WorkingDaysBetween = 0
End Function
这篇关于日期之间的经典 ASP 工作日数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文