Office中国论坛/Access中国论坛

标题: 怎样获取每月的实际工作日(即不包括周六日) [打印本页]

作者: 4848    时间: 2009-2-4 10:52
标题: 怎样获取每月的实际工作日(即不包括周六日)
请问:怎样获取每月的实际工作日(即不包括周六日)
作者: Henry D. Sy    时间: 2009-2-4 21:17
判断
如果是周六日,就扣掉相应的天数
作者: ACMAIN_CHM    时间: 2009-2-4 22:13
简单的计算方法。如下这个函数可以粗略的实现去除周六,周日。

Public Function wkday(bdt As Date, edt As Date) As Integer
    Dim dtemp As Date
   
   
    If bdt > edt Then
        dtemp = edt
        edt = bdt
        bdt = dtemp
    End If
   
    If Weekday(bdt, vbMonday) >= 6 Then
        bdt = bdt + 8 - Weekday(bdt, vbMonday)
    End If
   
    If Weekday(edt, vbMonday) >= 6 Then
        edt = edt - (Weekday(edt, vbMonday) - 5)
    End If
   
    Dim n As Integer
    n = edt - bdt + 1
    n = n - 2 * Int(n / 7)
    If Weekday(bdt, vbMonday) > Weekday(edt, vbMonday) Then
        n = n - 2
    End If
   
    wkday = n
   
End Function



  1. ?wkday(#2/1/2009#,#2/14/2009#)
  2. 10
  3. ?wkday(#2/8/2009#,#2/13/2009#)
  4. 5
复制代码




******************
*  一切皆有可能  *
******************

QQ群 48866293 / 12035577 / 7440532 / 13666209
http://forum.csdn.net/SList/Access .
http://www.accessbbs.cn/bbs/index.php .
http://www.accessoft.com/bbs/index.asp .
http://www.access-programmers.co.uk/forums .
http://www.office-cn.net .
.
http://www.office-cn.net/home/space.php?uid=141646 .
作者: ACMAIN_CHM    时间: 2009-2-4 22:20
但比较细致的做法,因为各企业的排班情况不同,特别是部分法定假日的不确定性(春节,中秋)。
一般来说是做一个日期表 calendar (cdate,cmode)
CDATECMODE
1/1/20099
1/2/20091
1/3/20090
1/4/20090
1/5/20091
1/6/20091
1/7/20091
1/8/20091
1/9/20091
1/10/20090
1/11/20090
1/12/20091
1/13/20091
1/14/20091
1/15/20091
1/16/20091
1/17/20090
1/18/20090
1/19/20091
1/20/20091
1/21/20091
1/22/20091
1/23/20091
1/24/20090
1/25/20099
1/26/20099
1/27/20099
1/28/20090
1/29/20091
1/30/20091
1/31/20090
2/1/20090
2/2/20091
2/3/20091
2/4/20091
2/5/20091
2/6/20091
2/7/20090


这样如计算d1,d2之间工作日,可以用查询

select count(*) from calendar where cmode=1 and cdate between #2009-01-01# and #2009-02-01#;



******************
*  一切皆有可能  *
******************

QQ群 48866293 / 12035577 / 7440532 / 13666209
http://forum.csdn.net/SList/Access .
http://www.accessbbs.cn/bbs/index.php .
http://www.accessoft.com/bbs/index.asp .
http://www.access-programmers.co.uk/forums .
http://www.office-cn.net .
.
http://www.office-cn.net/home/space.php?uid=141646 .
作者: ycxchen    时间: 2009-2-5 08:33
按4楼的办法,岂不是每年都要制一表?
作者: 咱家是猫    时间: 2009-2-5 09:12
陈格曾发布过一个较完整的函数,你可以搜索下access911网站
作者: 4848    时间: 2009-2-5 09:23
但比较细致的做法,因为各企业的排班情况不同,特别是部分法定假日的不确定性(春节,中秋)。
一般来说是做一个日期表 calendar (cdate,cmode)
CDATECMODE1/1/200991/2/200911/3/200901/4/200901/5/200911/6/2009 ...
ACMAIN_CHM 发表于 2009-2-4 22:20

此方法虽然比较麻烦,但是计算准确,谢谢指点!
作者: ycxchen    时间: 2009-2-6 08:40
请问,4楼表中CMODE中的1、0、9等表示什么意思?
作者: 4848    时间: 2009-2-7 13:43
我的理解是:0表示星期六、星期天;1表示工作日;9表示假日。
作者: huzaixin    时间: 2009-7-14 22:01
Public Function WeekDayCount(firstDate As Date, LastDate As Date) As Integer
'计算工作日天数
    On Error GoTo Err:

    Dim i As Integer
    Dim TempDate As Date    '临时日期
    Dim Tempts As Long
    Tempts = DateDiff("d", firstDate, LastDate)
    For i = 0 To Tempts
        TempDate = DateAdd("d", i, firstDate)
        Select Case Format(TempDate, "w")
        Case 2, 3, 4, 5, 6
            WeekDayCount = WeekDayCount + 1
        End Select
    Next
Err:
    Exit Function

End Function
作者: YXH_YXH    时间: 2013-5-22 17:47
huzaixin 发表于 2009-7-14 22:01
Public Function WeekDayCount(firstDate As Date, LastDate As Date) As Integer
'计算工作日天数
    O ...

请问有实例么!多谢。
作者: YXH_YXH    时间: 2013-5-22 17:48
ACMAIN_CHM 发表于 2009-2-4 22:13
简单的计算方法。如下这个函数可以粗略的实现去除周六,周日。

Public Function wkday(bdt As Date, edt ...

请问有实例么!多谢。
作者: 竹笛    时间: 2013-5-23 15:42
如过光是去周六周日的话先要判断当前月份天数 然后在循环判断是否为周六周日 如果是去掉.......不过确实不怎么实用因为还有好多国定假期呢
作者: aslxt    时间: 2013-5-23 19:11
Function MyNetworkDays(ByVal d1 As Date, ByVal d2 As Date) As Long
  '要引用 microsoft excel XX.0 object library
   Dim objExcel As Excel.Application
   Set objExcel = CreateObject("Excel.Application")
   MyNetworkDays = objExcel.Application.NetworkDays(d1, d2)
   objExcel.Quit
   Set objExcel = Nothing
End Function
作者: aslxt    时间: 2013-5-23 19:14
本帖最后由 aslxt 于 2013-5-23 19:20 编辑

NETWORKDAYS(start_date,end_date,holidays)
这个是excel的表函数,只是引用而已。执行起来有点慢,因为要打开excel和关闭excel。大侠们可有更好的方法?
第三个参数,可以自己定义(其实就是特定的节假日)
[attach]51837[/attach]




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3