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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine the date for the Friday of a given Year and week Number

Status
Not open for further replies.

Fiat77

Programmer
Feb 4, 2005
63
US
If on my report I have the Year in field Txt_Year and I have the Week Number in field Txt_Week, what function can i use to determine the datae for Friday.

Example Txt_Year returns 2005
Txt_Week returns 20
I need a text box named Txt_Date to return 5/13/2005 which is the corresponding Friday for those Year and week Number Parameters. How can i do this? Thank
 
This?

DATEADD("d",7*(txtwk-2)+vbfriday,"01/01/"& txtyear)
 
Fiat77,

sorry, in my way home remembered that this works for me for 2005 only and not for week=1

Try this one
Code:
Function FindDayInWeeks(TheWeek As Integer, TheYear As Integer, TheDay As String) As Date
Dim i As Integer
Dim DaysWeek As Integer
For i = 1 To 7
    If Format(DateSerial(TheYear, 1, i), "ddd") = TheDay Then Exit For
Next
DaysWeek = Format(DateSerial(TheYear, 1, i), "ww")
FindDayInWeeks = DateAdd("ww", TheWeek - DaysWeek, DateSerial(TheYear, 1, i))
End Function
and if week =1 then check this

year(FindDayInWeeks)<TheYear

because the 1st week of every year doesn't always have all the days!This year's 1st week had Saturday and Sunday only.

Call this function like

x=FindDayInWeeks(20,2005,"Your_DDD_FormatOfFriday")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top