Reply to topic
cfloop dates and then use in a query
windsorben


Joined: 07 Feb 2007
Posts: 13
Reply with quote
Can anyone show me what the code would look like for looping through two weeks of dates and then using those dates as a WHERE statement in a query. In other words, I want to retrieve the results of a query that match the date of the cfloop.
Thanks!
bobclingan
Forum Regular

Joined: 16 Sep 2004
Posts: 271
Location: Abingdon, MD
Reply with quote
Dates are natively supported by the cfloop tag already.

Code:

<cfset startDate = Now()>
<cfset endDate = Now() + 30>
<cfloop from="#startDate#" to="#endDate#" index="i" step="#CreateTimeSpan(7,0,0,0)#">
  <!--- your query here --->
</cfloop>
How do I write the select WHERE statement
windsorben


Joined: 07 Feb 2007
Posts: 13
Reply with quote
Thanks for your help. Now, how do I write the WHERE statement?

WHERE Date = <cfoutput>#i#</cfoutput>


And, if so, will it run through all the dates?
This is my first time at using a loop. Thanks for your help.
bobclingan
Forum Regular

Joined: 16 Sep 2004
Posts: 271
Location: Abingdon, MD
Reply with quote
That's correct.

SELECT foo
FROM bar
WHERE theDate = #i#
thank you
windsorben


Joined: 07 Feb 2007
Posts: 13
Reply with quote
I'll give it a shot! Appreciate you taking time out to help a beginner. Very Happy
palyne


Joined: 23 Oct 2006
Posts: 13
Reply with quote
I just wanted to thank Bob Clingan whose simple code clip, by accident, solved a problem I've had for six months with making an assignments rota app. Thanks man!!
bobclingan
Forum Regular

Joined: 16 Sep 2004
Posts: 271
Location: Abingdon, MD
Reply with quote
Glad I could be of service Very Happy
cfloop dates and then use in a query
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic