dealing with empty date strings

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

  1. #1

    Default dealing with empty date strings

    Have a query that pulls out the closest delivery date to today’s date, from
    two columns in a table. These columns are airdate and seadate and are the
    date type with a default as ‘’. usually, for each record, there will be only
    one of the columns with an actual date,the other set to the ‘’ default. It’s
    this default that I’m not sure how to deal with. The SQL to get the closest
    date is pretty crazy but it works and the best anyone could come up with :).
    The DB is MySQL4.1. Here’s the SQL:

    select colourid, adddate(curdate(), min(datediff(airdate,curdate()))) as
    airdate, adddate(curdate(), min(datediff(seadate,curdate()))) as seadate

    from purchase as p, stock as s

    where s.modelid=<cfqueryparam value="#url.ModelID#">

    and p.pending=1

    and s.pid=p.pid

    and (datediff(airdate,curdate())) >=0

    and (datediff(seadate,curdate())) >=0

    group by colourid

    It works fine if both the seadate and airdate have normal date values in
    them, but it returns no records if either of these colums has the default
    date of ‘’. How do I deal with that?


    --
    Cheers,
    Lossed
    __when the only tool you have is a hammer, everything looks like a nail __


    Lossed Guest

  2. Similar Questions and Discussions

    1. PDWordGetString makes empty strings?
      Hi, I'm writing a plug in using SDK 7.0.5 that needs to analyze the text in a PDF document. In order to test the code, I'm using message boxes to...
    2. #40394 [NEW]: mssql_bind() converts empty strings to null
      From: rnerovich at gmail dot com Operating system: XP/2003 server PHP version: 5.2.0 PHP Bug Type: MSSQL related Bug...
    3. Dealing with empty fields from database query
      Using the procedure in the Dreamweaver manual for building search/result pages I'm trying to retrieve data from MYSQL database and put it into a...
    4. Problems with empty strings and Properties window
      I need to be able to set a string property in a control to an empty string using the properties window. The problem is that when I set the...
    5. empty strings vs nulls
      How can I test for empty strings and nulls on a particular value. When I get an empty string or a null value I need to do something. Thanks in...
  3. #2

    Default Re: dealing with empty date strings

    What do you want to happen with these lines if airdate and/or seadate is NULL?

    and (datediff(airdate,curdate())) >=0
    and (datediff(seadate,curdate())) >=0

    In other words, do you want them to be ignored, evaluate as true, or evaluate
    as false if the date column is NULL?

    I'm not a MySQL user, but I believe that the sample below will behave as a
    "don't care" condition if the date column is NULL, so that it will evaluate as
    TRUE if it is NULL. In other words, if airdate or seadate is NULL, then it is
    replaced by curdate(), and since the difference between curdate() and curdate()
    is 0, the statement will be TRUE if the column is NULL, and it will behave as
    if the line was not included in the query.

    and (datediff(IFNULL(airdate,curdate()),curdate())) >=0
    and (datediff(IFNULL(seadate,curdate()),curdate())) >=0

    Phil


    paross1 Guest

  4. #3

    Default Re: dealing with empty date strings

    tks :)

    "paross1" <webforumsuser@macromedia.com> wrote in message
    news:d3ebre$bgm$1@forums.macromedia.com...
    > What do you want to happen with these lines if airdate and/or seadate is
    > NULL?
    >
    > and (datediff(airdate,curdate())) >=0
    > and (datediff(seadate,curdate())) >=0
    >
    > In other words, do you want them to be ignored, evaluate as true, or
    > evaluate
    > as false if the date column is NULL?
    >
    > I'm not a MySQL user, but I believe that the sample below will behave as
    > a
    > "don't care" condition if the date column is NULL, so that it will
    > evaluate as
    > TRUE if it is NULL. In other words, if airdate or seadate is NULL, then it
    > is
    > replaced by curdate(), and since the difference between curdate() and
    > curdate()
    > is 0, the statement will be TRUE if the column is NULL, and it will behave
    > as
    > if the line was not included in the query.
    >
    > and (datediff(IFNULL(airdate,curdate()),curdate())) >=0
    > and (datediff(IFNULL(seadate,curdate()),curdate())) >=0
    >
    > Phil
    >
    >

    Lossed 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