Order By Date/Time Issue

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

  1. #1

    Default Order By Date/Time Issue

    While this is more an annoyance than a problem, I'm wondering if it's something
    I'm doing or systematic.

    I'm running the query below to pull meetings based on a selected date from a
    previous form and organize those meetings by start time.

    <cfquery name="openmeetings" datasource="Scheduling">
    SELECT *
    FROM meetings
    WHERE program_code = '2006SU'
    AND event_code = '#form.date#'
    AND meeting_type = 'FACM'
    AND num_attendees < max_attendees
    ORDER BY start_time
    </cfquery>

    I get the proper results, but they're not sorted by start time. After trying
    a million different DatePart, LSTimeFormat, and TimeFormat functions in the
    'order by' statement (none of which worked), I finally tried just running a
    query of queries shown below to test if that would work.

    <cfquery name="haha" dbtype="query">
    SELECT *
    FROM openmeetings
    ORDER BY start_time
    </cfquery>

    This produced all the correct results AND ORDERED THEM PROPERLY BY TIME. I
    can't figure out why. The database I'm pulling from is MS Access, the
    start_time field is set to date/time format, although many of the entries are
    "2:00 pm" or "11:00 am" instead of a full defined date and time. The query
    result for the start_time field is always something like1899-12-30 11:10:00.0

    Like I said, it's only a minor inconvenience to run the extra query to sort
    the results, but can anyone explain why the original query won't?? Any help is
    appreciated.

    Trevor

    Trevor at IU Guest

  2. Similar Questions and Discussions

    1. Flex 2 Beta 3 date & daylight savings time issue
      I have created an addDay method which takes a date as a parameter and then adds 34 * 60 * 60 * 1000 to it, creates a new date and returns it, but...
    2. CFMX7.0.1 Administrator date time issue showing 13hrsbehind server time
      I am running a W2k SP4 box that has been upgraded from CFMX6 to CFMX7.0.1. The CFMX7.0.1 server is showing the date on the Server Settings >...
    3. Date/Time Issue
      The code looks okay. Are "EventTime" and "EventTimeTo" date/time columns in your table? If you output the query values without the LSTimeFormat()...
    4. Order by Date then ID
      I have a query that orders things by date. The database itself only has dates in it, not times, so what I want to do is find items in the database...
  3. #2

    Default Re: Order By Date/Time Issue

    Did you use the function CreateODBCDateTime() when populating the start_time
    column? The value "1899-12-30 11:10:00.0" already gives an indication why there
    might be problems.

    For most operating systems and databases, and I would presume, for MSAccess,
    too, the zero value relative to which dates are measured is '1970-01-01
    00:00:00' UTC. Sorting by date may not be possible if the start_time column
    has dates before that value. I am therefore guessing that the reason the
    sorting by query of query works because it is done by Coldfusion, which allows
    datetimes before 1970. Just an idea.



    BKBK Guest

  4. #3

    Default Re: Order By Date/Time Issue

    What you said seems to be consistent with what I'm seeing. As the data source
    is littered with inaccurate dates, it looks like running a second query is the
    easiest manner of fixing this. I'm glad to know that it was nothing my sytax
    of anything like that. Thanks for the input!!

    Trevor at IU Guest

  5. #4

    Default Re: Order By Date/Time Issue

    What's your database? Most (all?) DB's have functions to suck out only the
    time or date. For example in Access:
    ORDER BY Format(StartTime,'HH:MM:SS')
    then you could skip the overhead of an extra query.

    JMGibson3 Guest

  6. #5

    Thumbs up Re: Order By Date/Time Issue

    Simple solution...
    SELECT * FROM table_name ORDER BY dt desc, ORDER BY TM DESC;

    dt is date type,
    tm is time type.
    Avinash 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