统计某个日期区间内星期天的个数_Access数据库教程
推荐:浅析通用删除某表某字段满足条件的记录两个函数一、调用方式: Sub Acchelp_Test() '如果是条件是长整型 Call AccHelp_DeleteFldNumRow(表名称, 字段名称, 条件) '如果是条件是文本型 'Call AccHelp_DeleteFldStrRow(表名称, 字段名称, 条件) End Sub 二、两个函数: Public Function AccHelp_Del
文章正文:'功能:算出某个日期区间内星期天的个数
'作者:竹笛
'修改历史: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允许的九种数据类型在表的设计视图中,每一个字段都有设计类型,Access允许九种数据类型:文本、备注、数值、日期/时间、货币、自动编号、是/否、OLE对象、超级链接、查询向导。 文本:这种类型允许最大255个字符或数字,Access默认的大小是50个字符,而且系统只保存输入到字段
- 相关链接:
- 教程说明:
Access数据库教程-统计某个日期区间内星期天的个数。