I have a page that I want to run some reports on using ColdFusion and a SQL Server database.
Here is my form:
<cfform name="dateRange" action="" method="POST">
<label>Date From</label><br>
<cfinput type="DateField" name="dFrom" mask="DD/MM/YYYY">
<label>Date To</label><br>
<cfinput type="DateField" name="dTo" mask="DD/MM/YYYY">
<cfinput type="submit" value="Submit" name="Submit">
</cfform>
<hr>
<cfif isDefined("form.submit")>
<cfinclude template="data-p.cfm">
</cfif>
The data-p.cfm file looks like this:
<cfset fromDate = #CREATEODBCDATETIME(#form.dFrom#)#>
<cfset toDate = #CREATEODBCDATETIME(#form.dTo#)#>
<cfquery name="t">
SELECT id, type, started
FROM t_users
WHERE started >= #fromDate#
AND started <= #toDate#
ORDER BY started
</cfquery>
<cfdump var="#t#">
However the issue is that it dumps out all of the records and doesn't apply the date filter. When I dump the query it dumps all the records in the DB. It ignores the WHERE statement even though the SQL dump states:
SELECT id, type, started
FROM t_users
WHERE started >= {ts '2017-01-06 00:00:00'}
AND started <= {ts '2017-08-06 00:00:00'}
ORDER BY started
Any ideas?