Forum Moderators: open

Message Too Old, No Replies

ASP Date functions

loopy

         

klewlis

4:03 pm on Jan 3, 2002 (gmt 0)



hi!

I have a db table containing events and announcements, and dates and details of each. On my page I'm listing them a week at a time. So, for example, when you come to the announcements page you'll see the announcements for this week, and then you can move to "next week" or "previous week".

I'm using ASP's DatePart("ww", Date) to find the current week number, then finding the announcements that fall in that week. Then for "next" and "previous", I just adjust the week number and pass it through a querystring. That's all working fine. The part that's stumping me is this:

I also want to display on each page "Week of (startingdate) to (endingdate)". But I can't figure out a decent way to find out those two bits *from the week number*. For example, this is week number 1 of 2002. How can I get ASP to tell me from that information alone what the date was on sunday and what saturday's date will be?

Any ideas? Anything I've come up with so far has been long and complicated and not worth it for the tiny results... :)

klewlis

6:37 pm on Jan 3, 2002 (gmt 0)



nevermind, I backtracked a bit and figured out a better way:


'get today's date
'find out what weekday it is
myDate = DatePart("w", Date)

If Request.QueryString("week") = "" Then
'subtract to sunday and get the starting date for the week
startDate = Date - (myDate - 1)
Else
startDate = cDate(Request.QueryString("week"))
End If

'add 6 to get the ending date
endDate = startDate + 6

'next week and last week can be found by adding and subtracting 7 from start date
nextWeek = startDate + 7
lastWeek = startDate - 7

'display this week's start and end dates
Response.Write "<p align='center'><b>Week of " & GetMonthName(Month(startDate)) & " " & Day(startDate) & " to " & GetMonthName(Month(endDate)) & " " & Day(endDate) & ", " & Year(endDate) & "</b></p>"
'find all the events between start and finish
theVoid = "True"
%>
<p align="center"><a href="default.asp?page=announcements&week=<%=lastWeek%>"><< Previous</a> ¦ <a href="default.asp?page=announcements">This Week</a> ¦ <a href="default.asp?page=announcements&week=<%=nextWeek%>">Next >></a></p>
<%
strSQL = "SELECT * FROM [table] ORDER BY date"
Set objRS = conn.Execute(strSQL)
Do While NOT objRS.EOF
If objRS("date") >= startDate AND objRS("date") <= endDate Then
theVoid = "False"
Response.Write "<p><b>" & objRS("title") & "</b> (" & objRS("date") & ")<br>" & objRS("content") & "</p>"
End If
objRS.MoveNext
Loop

If theVoid = "True" Then
Response.Write "<p>Nothing is scheduled for this week.</p>"
End If