设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12下一页
返回列表 发新帖
查看: 4107|回复: 14
打印 上一主题 下一主题

[模块/函数] 怎样获取每月的实际工作日(即不包括周六日)

[复制链接]
跳转到指定楼层
1#
发表于 2009-2-4 10:52:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问:怎样获取每月的实际工作日(即不包括周六日)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2009-2-4 21:17:56 | 只看该作者
判断
如果是周六日,就扣掉相应的天数
3#
发表于 2009-2-4 22:13:12 | 只看该作者
简单的计算方法。如下这个函数可以粗略的实现去除周六,周日。

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 .
4#
发表于 2009-2-4 22:20:12 | 只看该作者
但比较细致的做法,因为各企业的排班情况不同,特别是部分法定假日的不确定性(春节,中秋)。
一般来说是做一个日期表 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 .
5#
发表于 2009-2-5 08:33:51 | 只看该作者
按4楼的办法,岂不是每年都要制一表?
6#
发表于 2009-2-5 09:12:27 | 只看该作者
陈格曾发布过一个较完整的函数,你可以搜索下access911网站
7#
 楼主| 发表于 2009-2-5 09:23:38 | 只看该作者
但比较细致的做法,因为各企业的排班情况不同,特别是部分法定假日的不确定性(春节,中秋)。
一般来说是做一个日期表 calendar (cdate,cmode)
CDATECMODE1/1/200991/2/200911/3/200901/4/200901/5/200911/6/2009 ...
ACMAIN_CHM 发表于 2009-2-4 22:20

此方法虽然比较麻烦,但是计算准确,谢谢指点!
8#
发表于 2009-2-6 08:40:37 | 只看该作者
请问,4楼表中CMODE中的1、0、9等表示什么意思?
9#
 楼主| 发表于 2009-2-7 13:43:57 | 只看该作者
我的理解是:0表示星期六、星期天;1表示工作日;9表示假日。

点击这里给我发消息

10#
发表于 2009-7-14 22:01:03 | 只看该作者
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-20 20:48 , Processed in 0.099637 second(s), 34 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表