Querying a timestamp

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

  1. #1

    Default Querying a timestamp

    Hello all, Having a problem querying a timestamp for a date. This is my
    query: SELECT * FROM accessLog WHERE td = '03/05/05' In the database, td is a
    timestamp. The query is not returning any results, although I know there are
    several hundred entries for that date. Could someone please tell me what I am
    doing wrong? Thanks.

    trendline Guest

  2. Similar Questions and Discussions

    1. Querying available streams
      Hi, I was wondering if it is possible to programmatically query the streams that are available in a "streams/myInstance" folder. For example you...
    2. Querying two datasources, but how?
      Datasource HelpDesk - Tables: HelpDeskList A, Volunteers B, Datasource Employee - Tables: Employee C. A.Emailto, A.Entry_ID, A.Name B.Name,...
    3. int4 -> unix timestamp -> sql timestamp; abstime?
      Hello, what is the opposite of cast(extract('epoch' from now()) as int)? The only thing I found that works is cast(cast(... as abstime) as...
    4. [PHP] Querying a form
      Those links pretty much show how to use forms with php. What Im looking for is a way to post data to a form, and retrieve the following page's...
    5. Querying a form
      Im looking for links to tutorials, or if someone can post code here, where php can be used to query a form, so that I can retrieve its results....
  3. #2

    Default Re: Querying a timestamp

    Well, the only record you should return with that query is for March 5th, 2005
    exactly at midnight. A datetime or timestamp field contains the date AND time,
    in some cases down to the millisecond ('ts 03/05/05 00:00:00.000'). If you
    just want records by date, you'll have to use the BETWEEN operator. So, for
    March 5th, 2005, the query should read SELECT * FROM AccessLog WHERE td
    BETWEEN '03/05/2005' AND '03/06/2005' The reason you do this is because the
    database engine assumes midnight if you don't supply the time. So, to
    parameterize for what I assume is a passed date, SELECT * FROM AccessLog
    WHERE td BETWEEN '#form.querydate#' AND dateadd(d,1,'#form.querydate#') Check
    your flavor of DB for the existence of and syntax regarding DATEADD(). You can
    use CF date manipulation functions if necessary. HTH,

    philh Guest

  4. #3

    Default Re: Querying a timestamp

    Thanks for the answer. I just realized myself that in using the
    CreateODBCDateTime function, I got 00:00:00 for the time, hence there would be
    no match. You technique will work... I'm wondering instead of using the
    between function as you put it, I thought I would a less than greater than
    function to isolate the day. td < dateAdd(d,1,#form.queryDate#) td >
    dateAdd(d,-1,#form.queryDate#) Is there some sort of DatePart function I can
    use on td to pull out it's date? Something like DatePart(date, td) = '03/05/05'
    ?

    trendline Guest

  5. #4

    Default Re: Querying a timestamp

    BETWEEN is perfect for this sort of evaluation; it's the equivalent of >= |
    <=. There is no datepart for the calendar date. You'd have to construct it
    out of the various date parts (mm, dd,yyyy). I don't see why you need to do
    this. When you display it, use DateFormat(). When you query, don't worry
    about it because BETWEEN takes care of it.

    philh Guest

  6. #5

    Default Re: Querying a timestamp

    I have already implemented your suggestion and it works fine, I just wanted to
    educate myself by trying to see if there was some type of SQL or Coldfusion
    function to extract the date part from the timestamp. Something like the way
    the DatePart function pulls out a specific part of a date... didn't know if
    there was a function that would pull the date out of a timestamp. Thanks for
    the help.

    trendline 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