I am trying to select records based on a date range, this is the query, it
doesn't like the format of the form variables.
<cfquery Name="Requests" Datasource="#AuditSoftDSN#">
SELECT *
FROM SoftwareRequests
WHERE SoftwareRequests.DateAdded >= ##form.StartDate## AND
SoftwareRequests.DateAdded <= ##form.EndDate##
ORDER BY SoftwareRequests.DateAdded;
</cfquery>
The database is MS Access. Any help is appreciated.
ksmith - 31 Mar 2006 22:24 GMT
Your select statement works for me in the code I have attached. You are
probably running into a formatting issue with your dates. Using access it
makes sense to pass everything as an ODBCDateTime. Take a peak at my code
below. My data is:
query - Top 3 of 3 Rows
DATEADDED ID NAME
1 2006-03-31 16:00:15.0 1 firstadd
2 2006-03-31 16:00:19.0 2 nextadd
3 2006-03-31 16:00:27.0 3 final add
<cfif isDefined("form.StartDate")>
<cfquery Name="Requests" Datasource="FormRequests">
SELECT *
FROM SoftwareRequests
WHERE SoftwareRequests.DateAdded >= #form.StartDate# AND
SoftwareRequests.DateAdded <= #form.EndDate#
ORDER BY SoftwareRequests.DateAdded;
</cfquery>
<cfdump var="#Requests#">
<cfelse>
<cfform action="#cgi.script_name#" method="POST" name="test">
Start Date: <cfinput type="Text" name="startdate"
value="#CreateODBCDateTime(DateAdd("d", -1, Now())
)#" required="No"><br>
End Date: <cfinput type="Text" value="#CreateODBCDateTime(Now())#"
name="enddate" required="No"><br>
<input type="submit">
</cfform>
</cfif>