VBScript 或 VBA 中的 ISO 周数 [英] ISO week number in VBScript or VBA
本文介绍了VBScript 或 VBA 中的 ISO 周数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 VBScript 或 VBA 中获取某个日期的 ISO 周数?
How can I get the ISO week number of some date in VBScript or VBA?
推荐答案
首先要注意:
- 报告周年和周数很重要,因为日期的年份可能不同.
- 几个 Windows 组件包含一个错误,在上周一存在多年.
- It is important to report the week year along with the week number, as the date's year could be different.
- Several Windows components contain a bug for some years' last Monday.
根据我的经验,最简单、最清晰、最可靠的计算方法是:
In my experience the simplest, clearest and most robust way to compute this is:
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 开始计数.
This also returns the ISO day of the week, counting from 1 for Mondays.
这篇关于VBScript 或 VBA 中的 ISO 周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文