获取给定日期的星期数 [英] Get the week number from a given date

查看:82
本文介绍了获取给定日期的星期数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:

'DD/MM/YYYY
"1/1/2009" should give `1`
"31/1/2009" should give `5`
"1/2/2009" should also give `5`

Format("1/2/2009", "ww")返回6.

那么,如何获得正确的结果?

So, how can I get the correct result?

推荐答案

我在这里做两件事与您的期望不符,我认为: 假设您希望将1月1日作为第1周,并将星期日作为一周的第一天 因此,它具有从2008年12月28日星期日到2009年1月3日星期六的第1周.

It's doing two things here which don't match your expectations, I think: Assuming you want the week with Jan 1 in as week 1, and using Sunday as first day of the week So it has week 1 running from Sunday 28th December 2008 to Saturday 3rd Jan 2009.

第6周将通过这种方法在2月1日星期日开始.

Week 6 would begin on Sunday 1st Feb by this method.

第1周的ISO标准是包含1月的4天或一年的第一个星期四的ISO标准(表达同一事物的不同方式). 您可以指定这种计算方法以及一周的第一天:

The ISO standard is for week 1 to be the one containing 4 days of January, or the first Thursday of the year (different ways of expressing the same thing). You can specify this method of calculation and the first day of the week:

Format(SomeDate,"ww",vbMonday,vbFirstFourDays)

有关语法,请参见此处:

see here for syntax:

https://support. office.com/zh-CN/article/Format-Function-6F29D87B-8761-408D-81D3-63B9CD842530

这篇关于获取给定日期的星期数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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