week number - convert back to date

lala

Registered User.
Local time
Today, 06:40
Joined
Mar 20, 2002
Messages
741
i have a function that calculates FIRST DAY OF WEEK

i need to calculate first day of weeks for the year
how can i do this?

i was going to use week numbers, but how do i tell the function that this number is the number of the week?

or is there a better way of doing this?
 
Since you have the FirstDayOfWeek function ... (here is the I code use for that) ...

Code:
Public Function FirstDOW(ByVal dtDate As Date, Optional intWeekBegin As Integer = vbUseSystemDayOfWeek) As Date
'Returns the first day of the week of the passed date.
 
    FirstDOW = DateSerial(Year(dtDate), _
               1, _
               DatePart("y", dtDate, intWeekBegin) - (Weekday(dtDate, intWeekBegin) - 1))
 
End Function

You can then just add the number of the week you wish to use to the first day of the week of the year (note the assumption is that MONDAY is considered the first day of the week)...

DateAdd("ww",<weeknumber> - 1,FirstDOW(DateSerial(Year(Date()),1,1),vbMonday))
Examples:

Week 1:
? DateAdd("ww",1 - 1,FirstDOW(DateSerial(Year(Date()),1,1),vbMonday))
12/31/2007

Week 2:
? DateAdd("ww",2 - 1,FirstDOW(DateSerial(Year(Date()),1,1),vbMonday))
1/7/2008

Week 52:
? DateAdd("ww",52 - 1,FirstDOW(DateSerial(Year(Date()),1,1),vbMonday))
12/22/2008
 
Last edited:
thank you so much!!!
this is exactly what i needed
 

Users who are viewing this thread

Back
Top Bottom