Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date compare ?

Status
Not open for further replies.

daNewfie

Programmer
Oct 14, 2004
258
0
0
CA
I have a field called "posted" in the sql DB set to date/time

I want to write a query that will only return results of items posted within the last seven days

...
<cfquery...
...
where posted ?????
</cfquery>


Craig
 
falcon, that'll only work in certain databases, and furthermore, because you're using a function on the date column, the index will be ignored and the query will do a table scan

kevin had the right idea, let coldfusion pass in a date constant, which will allow the database to use the index

r937.com | rudy.ca
 
This is what I got and tried numerous variations but cant get it to work

getting Invalid token "d"
Code:
SELECT memberId, username, password, firstName, lastName, email, dateReg
    FROM members
	where dateReg  <cfqueryparam value="#qGetMembers.dateReg#("d",-7,#now()#)" cfsqltype="CF_SQL_DATE" />
 
the value for the CFQUERYPARAM should be the result of applying the coldfusion DateAdd function with a parameter of -7 days to the current date

... where dateReg >
<cfqueryparam
value="#DateAdd("d",-7,Now())#"
cfsqltype="CF_SQL_DATE" />

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top