Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / March 2006



Tip: Looking for answers? Try searching our database.

Help with query using dates

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ruckus50 - 31 Mar 2006 20:29 GMT
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>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.