You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何构建MS Access查询以返回当前日期后的第二个周六日期?

计算当前日期后第二个周六的实现方案

Excel公式方案

使用WEEKDAY函数以周一为一周起始(参数2),确保计算逻辑统一,公式如下:

=TODAY() + IF(WEEKDAY(TODAY(), 2) < 6, 13 - WEEKDAY(TODAY(), 2), 20 - WEEKDAY(TODAY(), 2))

验证示例

  • 当今日为2023年2月3日(周五,周数5):13-5=8,2023/2/3 +8天=2023/2/11,符合需求。
  • 当今日为周六(周数6):20-6=14,加14天得到两周后的周六。
  • 当今日为周日(周数7):20-7=13,加13天得到两周后的周六。

Access实现方案

查询表达式

直接在查询中添加计算字段,以周一为一周起始:

DateAdd("d", 
    IIf(Weekday(Date(), 2) < 6, 13 - Weekday(Date(), 2), 20 - Weekday(Date(), 2)), 
    Date()
) AS SecondNextSaturday

VBA函数

如果需要复用计算逻辑,可编写自定义函数:

Function GetSecondNextSaturday() As Date
    Dim currentWeekday As Integer
    currentWeekday = Weekday(Date, vbMonday) ' 周一为一周第1天,周六=6,周日=7
    Dim addDays As Integer
    
    If currentWeekday < 6 Then
        addDays = 13 - currentWeekday
    Else
        addDays = 20 - currentWeekday
    End If
    
    GetSecondNextSaturday = DateAdd("d", addDays, Date)
End Function

调用时直接使用GetSecondNextSaturday()即可返回目标日期。

内容的提问来源于stack exchange,提问作者Matt Gilbert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 13:01:10