AllExperts > Experts 
Search      

Active Server Pages Programming (ASP)

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Jeff Allen
Expertise
I can answer basic to intermediate questions related to Classic ASP.I can answer Intermediate to Advanced questions CSS& HTML, and basic questions about JavaScript and Ajax. I can also answer questions related to web page accessibility under US Section 508.

Experience
I have 8 years experience with HTML. I have been developing in ASP, VBScript and CSS for two years each. I also currently work as web developer.

Organizations
IWA-HWG

Education/Credentials
I have a BA in English with minors in Web Design and Scientific and Technical Writing

 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > Search by Date with DateAdd

Topic: Active Server Pages Programming (ASP)



Expert: Jeff Allen
Date: 8/22/2006
Subject: Search by Date with DateAdd

Question
Hi.

Well Im trying to make my search engine to post results according to the time that the user choose. For instance, theres a radio button called "3 months ago". If he clicks it, the search will show only results from 3 months ago.

The problem is that DateAdd is not working properly with this, dont know why. Here's the code:

Set rsWeb = Server.CreateObject("ADODB.Recordset")
rsWeb.ActiveConnection = MM_connWeb_STRING
if (request.querystring("period") = "3m") then rsWeb.Source = "SELECT *  FROM agency WHERE Title LIKE '%" + Replace(rsWeb__MMColParam, "'", "''") + "%' OR Intertitle LIKE '%" + Replace(rsWeb__MMColParam, "'", "''") + "%' OR Date LIKE '%" + Replace(rsWebtranspo__MMColParam, "'", "''") + "%' AND Date < #" & DateAdd("m",-3,date()) & "# ORDER BY Register DESC"
rsWebtranspo.CursorType = 0
rsWebtranspo.CursorLocation = 2
rsWebtranspo.LockType = 1
rsWebtranspo.Open()

rsWebtranspo_numRows = 0
%>

No errors happen, but the search shows results from all months. So, what's wrong with the code above? :(

Answer
Shouldn't you be using the DateDiff function for this though? So you would capture the current date in one variable and subtracting 3 months from that? So you just want Dates from three months ago and not three months ago until now try using DATE = instead od DATE <

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.