如何在VBScript或VBA中获取某个日期的ISO week number?
答案 0 :(得分:2)
首先,请注意:
根据我的经验,最简单,最清晰,最健壮的计算方法是:
Sub WeekNum(someDate, isoWeekYear, isoWeekNumber, isoWeekDay)
Dim nearestThursday
isoWeekDay = WeekDay(someDate, vbMonday)
nearestThursday = DateAdd("d", 4 - Int(isoWeekDay), someDate)
isoWeekYear = Year(nearestThursday)
isoWeekNumber = Int((nearestThursday - DateSerial(isoWeekYear, 1, 1)) / 7) + 1
End Sub
这也会返回一周的ISO日期,从星期一的1开始计算。
答案 1 :(得分:0)
在A1单元格中输入任意日期,然后运行以下代码...
Range("A2").FormulaR1C1 = "=INT((R1C-DATE(YEAR(R1C-WEEKDAY(R1C-1)+4),1,3)+WEEKDAY(DATE(YEAR(R1C-WEEKDAY(R1C-1)+4),1,3))+5)/7)"