The date from 53 weeks prior: What was it?

The solution involves utilizing a function where the message time is passed as an argument. Within this function, one can retrieve the information regarding the time passed in terms of seconds, minutes, hours, days, months, or years. To address the issue, one can develop their own logic and determine their definition of the first week of the year, subsequently adjusting the usage of the DatePart function accordingly.


Solution:

The determination of the “first week of the year” appears to be contingent on the specific week being considered.

DatePart( "ww", "12/31/2010", vbMonday )
' returns 53
' FirstWeekOfYear parameter defaults to vbFirstJan1
' the week that contains January/01/2010
' here, its the week starting on December/28/2009
DatePart( "ww", "12/31/2010", vbMonday, vbFirstFourDays )
' returns 52
' FirstWeekOfYear parameter set to vbFirstFourDays
' the first week that has at least four days of the new year
' here, its the week starting on January/04/2010
DatePart( "ww", "12/31/2010", vbMonday, vbFirstFullWeek )
' returns 52
' FirstWeekOfYear parameter set to vbFirstFullWeek
' the first week that has full seven days of the new year
' here, again, its the week starting on January/04/2010

Determine your own interpretation of the initial week of the year, and utilize the DatePart function accordingly.

Frequently Asked Questions