Print Page | Close Window

ASP Date Select

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3165
Printed Date: 29 March 2026 at 5:01pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: ASP Date Select
Posted By: phorne
Subject: ASP Date Select
Date Posted: 31 May 2003 at 6:13am

I have the following code that selects records starting with the current date..

I want to be able to select dates 7 days from the current date - and then maybe 30 days from the current date - my attempts fail - but then I am not too good at this stuff!!

Would appreciate help!!!!!!!!!

Current Code:

strSQL = "SELECT events.* FROM events where date >= Date() order by date;"




Replies:
Posted By: ljamal
Date Posted: 31 May 2003 at 6:32am
Is that seven days before the current date and thirty days after the current date?

strSQL = "select * from events where date >= "&DateAdd("d",-7, date)&" and Date<="&DateAdd("d",30,date)&" order by date;"

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: phorne
Date Posted: 31 May 2003 at 6:39am

Days from the current date - start with today and go out a number of days -

You post helped alot - trying it now!



Posted By: phorne
Date Posted: 31 May 2003 at 6:54am

Tried code several ways - it did not give an error message of any kind - but did not display any records either! ( Also realize now I should probably not named field date - won't in the future but have many pages I have to change to correct that!!)

Current code:

strSQL = "select * from events where date >= Date() and Date<="&DateAdd("d",7,date)&" order by date;"



Posted By: pmormr
Date Posted: 31 May 2003 at 9:57am

right now your SELECT statement is saying 'WHERE date >= Date()" you must close your quotes in order to the current date. Try this

strSQL= "SELECT * FROM events WHERE date >="&date()&"and date <="&dateadd("d",7,date)&" ORDER BY date;"

try this. Hope i helped



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: phorne
Date Posted: 31 May 2003 at 12:10pm

Nope Neither of the above work!

No error messages - just no data displayed!

In trying to get the syntex correct I added a second "where":

strSQL= "SELECT * FROM events where date >="&date()&"and where date <="&dateadd("d",7,date) &" ORDER BY date;"

This also did not work but in the error message I do see that we are picking up the dates - just not the corect format yet! Error message:

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'date >=5/31/2003and where date <=6/7/200'.

Complete Code I am using:

<%
'Dimension variables
Dim adoCon    'Holds the Database Connection Object
Dim rsevent   'Holds the recordset for the records in the database
Dim strSQL   'Holds the SQL query for the database

'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("midga.mdb")

'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=midga"

'Create an ADO recordset object
Set rsevent = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL= "SELECT * FROM events where date >="&date()&"and where date <="&dateadd("d",7,date) &" ORDER BY date;"

 


'Open the recordset with the SQL query
rsevent.Open strSQL, adoCon


'Loop through the recordset
Do While not rsevent.EOF
 'Write the HTML to display the current record in the recordset
 Response.Write ("<br>")
 Response.Write ("<a href=""display_form.asp?ID=" & rsevent("ID") & """>") 
 Response.Write (rsevent("Date"))
 Response.Write ("</a>")
 Response.Write ("      ")
 Response.Write ("<b>")
 Response.Write (rsevent("eventname"))
 Response.Write ("</b>")
 Response.Write ("<br>")
' Response.Write (rsevent("church"))
' Response.Write ("<br>") 
' Response.Write (rsevent("eventtime"))
' Response.Write ("<br>") 
   Response.Write (rsevent("description"))
 Response.Write ("<br>")  
 
 'Move to the next record in the recordset
 rsevent.MoveNext

Loop

'Reset server objects
rsevent.Close
Set rsevent = Nothing
Set adoCon = Nothing
%>



Posted By: ljamal
Date Posted: 31 May 2003 at 12:42pm
Try this:
strSQL= "SELECT * FROM events where [date] >="&date()&"and [date] <="&dateadd("d",7,date) &" ORDER BY [date];"

You may be having problems because the field's name is date the brackets should eliminate that problem.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: phorne
Date Posted: 31 May 2003 at 8:31pm

Nope - that did not work either!! No error message - but no records displayed either!

 



Posted By: michael
Date Posted: 31 May 2003 at 8:57pm
strSQL = "SELECT * FROM events WHERE [date] Between now() AND dateadd(""d"",7,now())"
No need to mix asp; access know the dateadd function as well

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: phorne
Date Posted: 31 May 2003 at 9:10pm

Nope - that code did not work either and page would not display at all...

 

Do I need to go back and change the name of the date field to something other than date??



Posted By: michael
Date Posted: 31 May 2003 at 10:38pm
Not if you keep it in []'s The code I wrote work 100% as I am using it myself successfully. You are doing something else wrong, or you use an old version of access that might not know the function.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: phorne
Date Posted: 01 June 2003 at 5:11am

Version of Access is 2000

All I am doing is taking the line of code that works:

strSQL = "SELECT events.* FROM events where date >= Date() order by date;"

and I cut and paste the code you guys have been sending me! (which I really appreciate!)

I am using an Iframe to load the page - but I don't think that is the problem as the code works fine with the line above....

You can see the page at: http://www.midgachristian.com/index1.asp - http://www.midgachristian.com/index1.asp

 

 



Posted By: phorne
Date Posted: 01 June 2003 at 5:19am

Michael - I went back and put your code in again and get this error:

 Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

/Events/display_select-test.asp, line 97

Thought it was because ther was no ";" at the end of the statement - added it in different places and then added an additional " - then the page would not display at all...

Sure it is something I am doing but I have been banging my head for days with this!!



Posted By: phorne
Date Posted: 01 June 2003 at 5:49am

PROBLEM SOLVED!!!!!!!!

User on forum at http://www.haneng.com/ - http://www.haneng.com/

gave me the code:

strSQL = "select * from events where date >= Date() and (( Date <= #"&DateAdd("d",7,date)&"#)) order by date;"

This works great!!!!

Now I am wondering if I can change the number of days to add with a variable a user can select to view a different number of days??




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net