Date question: How can I get a list of the date of every Friday?

M

michaaal

How can I get a list of the date of every friday of the year?

I realize this code is wrong, but maybe you'll see what I am after...

Sub GetFridayList()
For x = 1 to len(Date(2004))
if Date(2004,x)="Friday" then msgbox (Date2004)
Next
End Sub
 
D

dlbjr

Function GetFridays(intYear)
Dim ArDates(53)
intMax = -1
strStart = DateSerial(intYear,1,1)
strEnd = DateSerial(intYear,12,31)
intDay = DatePart("w",strStart)
If intDay < 5 Then
strStart = DateAdd("d", 5-intDay,strStart)
End If
If intDay > 5 Then
strStart = DateAdd("d", (7-intDay) + 5,strStart)
End If
For I = 0 To 53
strStart = DateAdd("ww",1,strStart)
If CDate(strStart) =< CDate(strEnd) Then
ArDates(i) = strStart
intMax = intMax + 1
End If
Next
GetFridays = Join(ArDates,",")
GetFridays = Left(GetFridays,Len(GetFridays) - (53 - intMax))
End Function
 
M

Manohar Kamath

Essentially, get the first Friday, then add 7 to the date until the end of
the year

<%
Dim firstDay
Dim firstWeekDay
Dim firstFriday
Dim everyFriday


firstDay = DateSerial(1, 1, 2004)

' Assuming Sunday is the first day of the week
firstWeekDay = WeekDay(firstDay, vbSunday)

' Compute the date of the first Friday
If vbFriday >= firstWeekDay Then
firstFriday = firstDay + (vbFriday - firstWeekDay)
Else
firstFriday = firstDay + (vbFriday - firstWeekDay) + 7
End If

everyFriday = firstFriday

' Now that you have the first Friday, loop until you hit the end of the year
Do While Year(everyFriday) = 2004
Response.Write("<br>" & everyFriday)
everyFriday = everyFriday + 7
Loop

%>
 
M

michaaal

Manohar Kamath said:
Essentially, get the first Friday, then add 7 to the date until the end of
the year

<%
Dim firstDay
Dim firstWeekDay
Dim firstFriday
Dim everyFriday


firstDay = DateSerial(1, 1, 2004)

' Assuming Sunday is the first day of the week
firstWeekDay = WeekDay(firstDay, vbSunday)

' Compute the date of the first Friday
If vbFriday >= firstWeekDay Then
firstFriday = firstDay + (vbFriday - firstWeekDay)
Else
firstFriday = firstDay + (vbFriday - firstWeekDay) + 7
End If

everyFriday = firstFriday

' Now that you have the first Friday, loop until you hit the end of the year
Do While Year(everyFriday) = 2004
Response.Write("<br>" & everyFriday)
everyFriday = everyFriday + 7
Loop

%>


You guys are the best. Thank you for the code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top