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

Discussion in 'ASP General' started by michaaal, Oct 4, 2004.

1. ### michaaalGuest

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

michaaal, Oct 4, 2004

2. ### Ray Costanzo [MVP]Guest

There is the Weekday function in VBScript that may work for you.
http://msdn.microsoft.com/library/en-us/script56/html/vsfctweekday.asp

installed, I strongly recommend that you do.

Ray at home

"michaaal" <> wrote in message
news:O2%...
> 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
>
>

Ray Costanzo [MVP], Oct 4, 2004

3. ### dlbjrGuest

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
End If
If intDay > 5 Then
strStart = DateAdd("d", (7-intDay) + 5,strStart)
End If
For I = 0 To 53
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

--
'dlbjr

dlbjr, Oct 4, 2004
4. ### Manohar KamathGuest

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

%>
--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com

"michaaal" <> wrote in message
news:O2%...
> 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
>
>

Manohar Kamath, Oct 4, 2004
5. ### michaaalGuest

Manohar Kamath" <> wrote in message
news:...
> 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
>
> %>
> --
> Manohar Kamath
> Editor, .netWire
> www.dotnetwire.com
>
>
> "michaaal" <> wrote in message
> news:O2%...
> > 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
> >
> >

>
>

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

michaaal, Oct 4, 2004