计算日期内多少周末? [英] calculate how many weekend days inside date?

查看:430
本文介绍了计算日期内多少周末?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算多少个周末2日期内?我的意思是,我有两个日期,并想知道周六和放大器的数量;这些日期之间的星期日。

I need to calculate how many weekend days inside 2 dates? what I mean is that I have 2 dates and want to know the count of Saturdays & Sundays between these dates.

我对每条记录的2日期(从日 - 至今),想查询周末的计数

I have the 2 dates on each record (from date - to date) and want to query the count of weekends.

推荐答案

下面的VBA功能将允许你运行表单的访问查询

The following VBA function will allow you to run Access queries of the form

SELECT CountWeekendDays([from date], [to date]) AS WeekendDays FROM YourTable

就在Access中创建一个新的模块并粘贴以下code到它:

Just create a new Module in Access and paste the following code into it:

Public Function CountWeekendDays(Date1 As Date, Date2 As Date) As Long
Dim StartDate As Date, EndDate As Date, _
        WeekendDays As Long, i As Long
If Date1 > Date2 Then
    StartDate = Date2
    EndDate = Date1
Else
    StartDate = Date1
    EndDate = Date2
End If
WeekendDays = 0
For i = 0 To DateDiff("d", StartDate, EndDate)
    Select Case Weekday(DateAdd("d", i, StartDate))
        Case 1, 7
            WeekendDays = WeekendDays + 1
    End Select
Next
CountWeekendDays = WeekendDays
End Function

这篇关于计算日期内多少周末?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆