【问题标题】:How to calculate the week number within a month, given Sun-Sat is the week如何计算一个月内的周数,给定周日至周六是一周
【发布时间】:2019-10-31 16:59:33
【问题描述】:

假设我的一周从周日开始,到周六结束。

给定一个日期,我想找到该月的周数,但也要考虑部分周数。例如,在这个日历中,http://cityofdefiance.com/wp-content/uploads/2019-calendar-3-e1545926721248.jpg

19 年 1 月 1 日:第 1 周
2019 年 1 月 6 日:第 2 周
2019 年 1 月 26 日:第 4 周
2019 年 1 月 28 日:第 5 周

19 年 2 月 1 日:第 1 周
19 年 2 月 28 日:第 5 周

01-Jun-19:第 1 周
2019 年 6 月 30 日:第 6 周

谢谢!

【问题讨论】:

    标签: math logic date-arithmetic


    【解决方案1】:

    我解决了。

    Month1stSunday = 8-Date.DayOfWeek(Date.StartOfMonth([FieldDate]), Day.Sunday)
    
    if (Date.Day([FieldDate]) <= [Month1stSunday]) then "W1" 
      else if (Date.Day([FieldDate]) <= [Month1stSunday]+7) then "W2" 
      else if (Date.Day([FieldDate]) <= [Month1stSunday]+14) then "W3" 
      else if (Date.Day([FieldDate]) <= [Month1stSunday]+21) then "W4" 
      else if (Date.Day([FieldDate]) > [Month1stSunday]+21) then "W5" 
    else ""
    

    可能不是很好,但工作正常。

    【讨论】:

      猜你喜欢
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多