Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - ASP Date Select
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ASP Date Select

 Post Reply Post Reply Page  12>
Author
phorne View Drop Down
Newbie
Newbie


Joined: 18 May 2003
Location: United States
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote phorne Quote  Post ReplyReply Direct Link To This Post Topic: ASP Date Select
    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;"

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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;"
Back to Top
phorne View Drop Down
Newbie
Newbie


Joined: 18 May 2003
Location: United States
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote phorne Quote  Post ReplyReply Direct Link To This Post 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!

Back to Top
phorne View Drop Down
Newbie
Newbie


Joined: 18 May 2003
Location: United States
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote phorne Quote  Post ReplyReply Direct Link To This Post 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;"

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
phorne View Drop Down
Newbie
Newbie


Joined: 18 May 2003
Location: United States
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote phorne Quote  Post ReplyReply Direct Link To This Post 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
%>

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
phorne View Drop Down
Newbie
Newbie


Joined: 18 May 2003
Location: United States
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote phorne Quote  Post ReplyReply Direct Link To This Post Posted: 31 May 2003 at 8:31pm

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

 

Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.