Help with query using dates

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Help with query using dates

    I am trying to select records based on a date range, this is the query, it
    doesn't like the format of the ##form.StartDate## and ##form.EndDate:

    <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.


    Ruckus50 Guest

  2. Similar Questions and Discussions

    1. How to you compare dates in a query in Mysql
      Dear friends, Plesae help in finding the correct syntax for comparing two dates in a query in MySql database Thank you Subodh Gupta
    2. Dates & SQL
      In my CF form I have created a date object using #DateFormat(Now(),"MM/DD/YY")# which displays the date as: 07/29/05. When the date is inserted...
    3. Query of Queries on query New type query
      In CF5 we have a page that creates a query, using queryNew and querySetCell and the like, we then used dbtype="query" and gave it's name so we could...
    4. ASP/VBS Dates Between Dates
      I'm trying to filter records depending on 2 dates requested from the querystring MMColParam1 (startdate) and MMColParam2 (enddate), i.e. a list...
    5. Dates again
      Hello all I'm having trouble getting iis to understand the UK format of dates ASP off a MS Access database I have the following query:...
  3. #2

    Default Re: Help with query using dates

    You don't need the # for the Access date type column from within ColdFusion.

    Try

    <cfquery Name="Requests" Datasource="#AuditSoftDSN#">
    SELECT *
    FROM SoftwareRequests
    WHERE SoftwareRequests.DateAdded >= #form.StartDate# AND
    SoftwareRequests.DateAdded <= #form.EndDate#
    ORDER BY SoftwareRequests.DateAdded;
    </cfquery>

    --or--

    <cfquery Name="Requests" Datasource="#AuditSoftDSN#">
    SELECT *
    FROM SoftwareRequests
    WHERE SoftwareRequests.DateAdded >= #CreateODBCDateTime(form.StartDate)# AND
    SoftwareRequests.DateAdded <= #CreateODBCDateTime(form.EndDate)#
    ORDER BY SoftwareRequests.DateAdded;
    </cfquery>

    Phil



    paross1 Guest

  4. #3

    Default Re: Help with query using dates

    #CreateODBCDateTime(form.StartDate)#, it worked using this format.

    #form.StartDate#, did not work.


    Thanks for your help.
    Ruckus50 Guest

  5. #4

    Default Re: Help with query using dates

    Welcome. I haven't used Access since using it with ColdFusion 4.5 so I wasn't sure which one might work the best.
    paross1 Guest

  6. #5

    Default Re: Help with query using dates

    I noticed that you used
    where dbdate>=#createodbcdate(form.startdate)#
    and dbdate<=#createodbcdate(form.Enddate)# .
    This has one problem:
    If startdate is 31/1/06 and Enddate is 3/31/06, you wont get data from
    3/31/06 if the datab ase field stores that data a date time (there will be a
    fraction greater than todays date). It does not mater if you use
    createodbcdate() or CreateODBCDateTime() if you r user is typing in 3/31/06.

    A better solution is to have your where cluse look like
    where dbdate>=#createodbcdate(form.startdate)#
    and dbdate<#createodbcdate(form.Enddate+1)# .
    This will also not mess up the databases use of indexes.

    ColdSteel2 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139