Get the week number from a given date

calendar_today Asked Oct 30, 2009
thumb_up 22 upvotes
history Updated April 14, 2026

Direct Answer

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…. This is an advisory response with reference links, ranked #22nd of 95 by community upvote score, from 2009.


The Problem (Q-score 8, ranked #22nd of 95 in the VBA Core archive)

The scenario as originally posted in 2009

Examples:

'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") returns 6.

So, how can I get the correct result?

Why community consensus is tight on this one

Across 95 VBA Core entries in the archive, the accepted answer here holds strong answer (top 25 %%) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — strong answer (top 25 %%) (+22)

Advisory answer — community consensus with reference links

Note: the verified answer below is a reference / advisory response rather than a copy-ready snippet.

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.

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

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/en-US/article/Format-Function-6F29D87B-8761-408D-81D3-63B9CD842530


When to Use It — vintage (14+ years old, pre-2013)

Ranked #22nd in its category — specialized fit

This pattern sits in the 82% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the VBA Core archive for a higher-consensus alternative.

What changed between 2009 and 2026

The answer is 17 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

Why does this sit in the top quartile of VBA Core answers?
expand_more

Answer score +22 vs the VBA Core archive median ~7; this entry is strong. The score plus 8 supporting upvotes on the question itself (+8) means the asker and 21 subsequent voters all validated the approach.

This answer links out — what are the reference links worth following?
expand_more

Read the first external link for the canonical reference, then search this archive for a top-10 entry in the same category — advisory answers are best paired with a ranked code snippet to close the loop.

This answer is 17 years old. Is it still relevant in 2026?
expand_more

Published 2009, which is 17 year(s) before today’s Office 2026 build. The VBA Core object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which VBA Core pattern ranks just above this one at #21?
expand_more

The pattern one rank above is “Finding similar sounding text in VBA”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 8, Answer-score 22, original post 2009, ranked #22nd of 95 in the VBA Core archive. Last regenerated April 14, 2026.

vba