Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date computation 1

Status
Not open for further replies.

strangeryet

Programmer
Jul 8, 2004
159
0
0
US
Hello,

How can I find what the Sunday date would be for the xx number of weeks represented as a numeric value:

In other words: If given the numeric value of (let's say) 37, what would the Sunday date be for the 37th week into the year?

I assume I would start with a beginnnig date of 010108
and do a dateadd("ww", begindate, 37) then step through and add 1 to each day until I find Sunday???
Thanks
 



Hi,

d is any date within the year of interest, w is the week.
Code:
Function SunDte(d As Date, w As Integer)
    Dim i
    
    d = DateSerial(Year(d), 1, 1)
    
    d = d + (w - 1) * 7
    Do
        i = Weekday(d)
        If i = 1 Then Exit Do
        d = d + 1
    Loop
    SunDte = d
End Function


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top