日期之间平日的经典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不包括所请求的操作,但是间隔ww
的DateDiff
返回两个日期之间的星期天数,从而确保开始和结束日期不在周末,我们可以直接计算工作日数:
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-(d\6 + d\7), d1)
' Move end date backward if it is a weekend
d = WeekDay( d2, vbMonday )
If d > 5 Then d2 = DateAdd( "d", -1*(d\6 + d\7), 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屋!
查看全文