统计某个日期区间内星期天的个数-张志
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> 综合其它


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

发表时间:2006/1/3 评论(0) 浏览(8005)  评论 | 加入收藏 | 复制
   
摘 要:统计某个日期区间内星期天的个数
正 文:
'功能:算出某个日期区间内星期天的个数
'作者:竹笛
'修改历史: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 = SundayCoun

Access软件网交流QQ群(群号:198465573)
 
 相关文章
[access查询]如何统计某一行某几个字段的个数?(答读者问题)  【王樵民  2009/11/27】
【Access示例】日期范围在星期一至星期天  【缪炜  2013/7/12】
【Access DCount示例】统计子窗体条件为空的记录数示例\...  【麥田  2014/5/2】
【Access自定义函数】取得指定月份星期天个数示例,获取当月的星...  【麥田  2014/6/19】
常见问答
技术分类
相关资源
文章搜索
关于作者

张志

文章分类

文章存档

友情链接