PDA

View Full Version : records dates and showing+links


scroots
10-22-2002, 10:14 PM
how can i show records with only certain dates in a field, e.g. i have a database calender and which to show the events on certain dates and the ones on that page. so to show todays on the page it would show yesterdays,todays, tommorows, thursdays, fridays and saturdays.
how can i do this?

also how can i have a link so when it is clicked it shows the calender with the next 6 days after the current dates showing?

thanks in advance

scroots

whammy
10-23-2002, 12:06 AM
"SELECT * FROM tablename WHERE DateTimeField BETWEEN(#" & Date()-1 & "# AND #" & Date()+4 & "#)"

That's assuming you're using Access... if you're using SQL Server replace the # marks with '.

That should also solve your second question. ;)

raf
10-23-2002, 09:08 AM
Whammy : good, better, ....

My code for the second question:



dim conEvents
set conEvents=server.CreateObject("adodb.connection")
conEvents.Open("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("businesses.mdb"))
dim rsUpcomming
set rsUpcomming= server.CreateObject("adodb.recordset")

dim currentdate, enddate
currentdate = date()
enddate= DateAdd("d", 7, date()) 'enddate returns actual date + 6 days.

'display calendar strates here
dim sql
sql="select Event_Name, ID, Start_Date from events where End_Date >= #thedate# and Start_Date <= #stopdate# order by Start_Date asc"
sql=replace(sql,"thedate",currentdate)
sql=replace(sql,"stopdate",enddate)

rsUpcomming.Open sql, conEvents

if rsUpcomming.EOF=true then
response.write("<font color='red'><b>No upcomming events for this week</b></font><br><br>")
else

do while rsUpcomming.EOF=false
if rsUpcomming.Fields("Start_Date") <= date () then
response.write("<font color='red'>Today : <a href=eventinfo.asp?eventID=" &rsUpcomming.Fields("ID") & ">" & rsUpcomming.Fields("Event_Name") & "</a></font><br>")
else
response.write("<a href=eventinfo.asp?eventID=" &rsUpcomming.Fields("ID") & ">" & rsUpcomming.Fields("Event_Name") & "</a><br>")
end if
rsUpcomming.MoveNext
loop
end if
'display calendar ends here

rsUpcomming.Close
set rsUpcomming=nothing

conEvents.Close
set conEvents = nothing



Pure coïncidence. Wrote it this week for someone else.
Advantages :
-number of days can be easily modifyed by user (using a form with a field to select number of days + replace 7 with variable in script)
-also displays current events that started in the past an stil run for more then six days
- dates are displayed as link so you can open a page with info about that event

scroots
10-23-2002, 06:14 PM
thank you both of you i will be trying out your solutions ot my problem.
thanx again

scroots

scroots
10-23-2002, 07:47 PM
raf, i`m using your way but it tells me i have no upcoming events, can you help me.
my access database has in it an event for yesterday, events in it upto the 2nd of november, some span more than one day.
my code:

<%
dim conEvents
set conEvents=server.CreateObject("adodb.connection")
conEvents.Open("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("guestbook.mdb"))
dim rsUpcomming
set rsUpcomming= server.CreateObject("adodb.recordset")

dim currentdate, enddate
currentdate = date()
enddate= DateAdd("d", 7, date()) 'enddate returns actual date + 6 days.

'display calendar strates here
dim sql
sql="select event, ID_NO, sdate from tblComments where edate >= #thedate# and sdate <= #stopdate# order by sdate asc"
sql=replace(sql,"thedate",currentdate)
sql=replace(sql,"stopdate",enddate)

rsUpcomming.Open sql, conEvents
if rsUpcomming.EOF=true then
response.write("<font color='red'><b>No upcomming events for this week</b></font><br><br>")
else

do while rsUpcomming.EOF=false
if rsUpcomming.Fields("sdate") <= date () then
response.write("<font color='red'>Today : <a href=eventinfo.asp?eventID_NO=" &rsUpcomming.Fields("ID_NO") & ">" & rsUpcomming.Fields("event") & "</a></font><br>")
else
response.write("<a href=eventinfo.asp?eventID_NO=" &rsUpcomming.Fields("ID_NO") & ">" & rsUpcomming.Fields("event") & "</a><br>")
end if
rsUpcomming.MoveNext
loop
end if
'display calendar ends here

rsUpcomming.Close
set rsUpcomming=nothing

conEvents.Close
set conEvents = nothing

%>

any help is apreciated.

scroots

whammy
10-24-2002, 12:34 AM
Actually BETWEEN runs faster, if I remember correctly (as opposed to <= >= etc.) but I could be wrong... I know it's a heck of a lot easier to code, though. :D

Besides, I thought my solution was a bit more elegant. But that's just my humble opinion.

How is your code better? ;)