动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   数据库 → 阅读文章

 统计某个日期区间内星期天的个数

作者来源: 
阅读 数 414 人次 , 2006-2-16 15:14:00 

文章正文:
'功能:算出某个日期区间内星期天的个数
'作者:竹笛
'修改历史:2005/12/30
'未经严格测试,有问题请与作者交流

Function SundayCount(StartDate As Date, EndDate As Date) As Long
    On Error GoTo Err_SundayCount:
    Dim Days As Integer    '区间天数
    Dim FirstSunday As Date    '第一个周日具体日期
    Dim NextSunday As Date    '下一个周日具体日期
    Dim Myweekday As Integer
    Dim i As Long
    Dim j As Long
    '确保日期都不为空,若为空则置为0
    If Not IsNull(StartDate) And Not IsNull(EndDate) Then
    '如果结束日期<开始日期,则为0
        If EndDate >= StartDate Then
            '如果天数大于7,则先确定第一个周日是哪个日期,再7天一加,直到大于结束日期
            Days = EndDate - StartDate
            ' If Days > 7 Then
            Myweekday = Weekday(StartDate)    '算出是周几,星期天是1
            If Myweekday > 1 Then
                FirstSunday = StartDate + 8 - Myweekday
            Else
                FirstSunday = StartDate
            End If
            Debug.Print "最近的周日是: " & FirstSunday
            NextSunday = FirstSunday + 7
            i = 1
            SundayCount = 1
            For i = 1 To Days Step 7
                Debug.Print "下一个周日是: " & NextSunday
                If NextSunday > EndDate Then
                    If FirstSunday > EndDate Then
                        SundayCount = SundayCount - 1
                    End If
                    Debug.Print "周日数目是: " & SundayCount
                    Exit Function
                End If
                NextSunday = NextSunday + 7
                i = i + 1
                SundayCount = SundayCount + 1
                Debug.Print "周日数目是: " & SundayCount
            Next
        Else
            SundayCount = 0
        End If
    Else
        SundayCount = 0
    End If
Exit_SundayCount:
    Exit Function
Err_SundayCount:
    SundayCount = 0
    Resume Exit_SundayCount
End Function

Sub Test()
Debug.Print SundayCount(#2/6/2005#, #2/25/2005#)
End Sub   

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:长期使用中型Access数据库的一点经验
· 下一篇:通用删除某表某字段满足条件的记录两个函数
· 如何识别真实和自动创建的索引?
· SQLPlus中的复制和粘贴技巧
· 关于MSSQL占用过多内存的问题
· DB2编程序技巧 (八)
· DB2企业内容管理产品的分析(1)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077