Automatically selecting date range

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

  1. #1

    Default Automatically selecting date range

    HI. I need to spend more time here so that when I visit I am not always asking
    questions. Anyway, here is my question fo today.

    I have a database that I use for customer and client information. The table
    has a date field that I use to pull out the records that I need to work on for
    a specific day. I can pul out records for any given date by using a form that I
    can plug the date into. there are 2 things that i would like to do. the first
    is to show the number of clients/records that I have for each of the next five
    days on my admin home page, as follows:

    Contacts for next five days:
    Today - 12
    10/19/05 - 11
    10/20/05 - 10
    10/21/05 - 15
    10/22/05 - 7

    I cannot determine how to use 5 seperate record sets that pull the records
    out. For the first specific day I assume to use a querry like this:

    <cfquery datasource="xxxx" name="qGetToday">
    SELECT *
    FROM ClientList
    WHERE ContactDate='#Form.date#'
    </cfquery>

    to display use: <cfoutput>#qGetToday.RecordCount#</strong></cfoutput>

    Don't know how to get the next 4 days worth ??? Or is there a simple/better
    way to accomplish this?

    The second thing I want to do is build a page that displays the records for
    each of the 5 days..
    EXAMPLE:


    Contact Today
    -----------------------------------------
    Record 1
    Record 2

    Contact on 10/19/05
    -----------------------------------------
    Record 1
    Record 2

    etc..

    Any help would be appriciated... Thanks, Chip :beer;:D



    chipjohns Guest

  2. Similar Questions and Discussions

    1. Error Selecting Timestamps - String Index out of Range
      We are running CFMX 6.1 on Linux Connecting to a PostgreSQL 7.X database cluster. When we try to perform a query that selects a timestamp from...
    2. Selecting First Row Automatically
      Is it possible to have the first row already selected in a Flash Form CFGRID whenever the page loads? If so, how? Thanks, -Jones
    3. Date Range
      I?ve got a routine that figure out 30 days from today?s date, but what I want to do is resolve a start date and an end date where the start date is...
    4. Date Range Search
      I have a calendar search from where an option is to search between dates and riight now it never finds anything. Do I need to do a format...
    5. Selecting a range of dates in MySql
      I need to do a search in MySql for birth date range. (i.e. for birth date Any suggestions on how to do this select? Thanks!
  3. #2

    Default Re: Automatically selecting date range

    If your database has date functions like dateadd, use them. Otherwise, use
    cold fusion to create a list of dates (or something like that) and use that in
    your query.

    To display your data, use the group attribute of the cfoutput tag.

    Dan Bracuk Guest

  4. #3

    Default Re: Automatically selecting date range

    chipjohns,

    So you want to display the totals on one page and the detail on a separate page? I assume there won't always be contacts for every date?
    mxstu Guest

  5. #4

    Default Re: Automatically selecting date range

    mxstu

    True , there most likely will be times when there will be days with no
    records...


    Dan

    I'm not familiar with the group function for cfoutput. Off I go to learn more.
    Thanks...

    Oh yes, I am using Access


    chipjohns Guest

  6. #5

    Default Re: Automatically selecting date range

    Will the totals and detail records be on a single page or two separate pages?
    mxstu Guest

  7. #6

    Default Re: Automatically selecting date range

    two seperate pages!
    chipjohns Guest

  8. #7

    Default Re: Automatically selecting date range

    >I cannot determine how to use 5 seperate record sets that pull the records out.
    You could do this in a single query, by getting the count(*) of records by
    contactdate, and then grabbing the TOP 5 records, ordered by contact date
    (ascending)

    How you output the information depends on what you want to display. Assuming
    you want to display the next (5) calendar dates, whether or not there are any
    contacts, one method is to loop through the query results and display the
    number of contacts if any exist. Otherwise, display zero. Note, there may be
    more efficient methods, but this should demonstrate the idea.





    <!--- Assumes "ContactDate" is a date/time field that contains a date ONLY (no
    time) --->
    <!--- Assumes "form.date" is a valid date string in mm/dd/yyyy format --->

    <cfquery name="getData" datasource="#yourDSN#">
    SELECT TOP 5 ContactDate, count(*) AS TotalContacts
    FROM ClientList
    WHERE ContactDate >= #createODBCDate(form.date)#
    GROUP BY ContactDate
    ORDER BY ContactDate ASC
    </cfquery>

    <cfset loopDate = createODBCDate(form.date)>
    <cfloop from="1" to="5" index="j">
    <!--- reset default --->
    <cfset NumberOfContacts = 0>
    <!--- find number of contacts for current date --->
    <cfloop query="getData">
    <cfif dateDiff("d", loopDate, contactDate) eq 0>
    <cfset NumberOfContacts = TotalContacts>
    <cfbreak>
    </cfif>
    </cfloop>
    <cfoutput>Contact Date: #DateFormat(loopDate, "mm/dd/yyy")# -
    #NumberOfContacts#</cfoutput><br>
    <!--- increment loop date --->
    <cfset loopDate = dateAdd("d", 1, loopDate)>
    </cfloop>

    mxstu Guest

  9. #8

    Default Re: Automatically selecting date range

    Since you are displaying stuff on two pages, you don't have to use cfoutput to
    group the data. You can do it with two queries.

    On the first page, your query will select date, count(date) as appointments.
    When you are displaying the results, wrap the date with an anchor tag and send
    that date as a url variable.

    Then on the 2nd page, use that variable to select the appointments for that
    date.

    Originally posted by: chipjohns
    mxstu

    True , there most likely will be times when there will be days with no
    records...


    Dan

    I'm not familiar with the group function for cfoutput. Off I go to learn more.
    Thanks...

    Oh yes, I am using Access




    Dan Bracuk Guest

  10. #9

    Default Re: Automatically selecting date range

    Thanks Dan and Stu ,

    I'm going to try and understand this and see if I can make it work..
    Thanks,
    chipjohns 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