Date comparison failure

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Date comparison failure

    Does this qualify as an advanced technique? Sorry if not. This is a section of
    stock control I am doing to track supplier orders. I have a two text input
    boxes, one has a value of #dateformat(NOW(), 'dd/MM/yyyy')# and the other is
    blank. When i process the form, a query puts these dates into a table with the
    following code. UPDATE tbl_supplierorders SET suporder_orderdate =
    #createodbcdate(dateformat(form.suporder_orderdate , 'dd/MM/yyyy'))#,
    suporder_duedate = #createodbcdate(dateformat(form.suporder_duedate,
    'dd/MM/yyyy'))# WHERE suporder_refID = <cfif URL.action EQ
    'view'>'#URL.suporder_refid#'<cfelse>'#session.sup ref_id#'</cfif> The fields
    in the table then list the dates in an english format (without the bracketed
    date, just showing you what it represents) 30/02/2005 (30th Feb) 01/12/2004
    (1st Dec) 03/04/2004 (3rd April) I list these on another page and compare
    them to todays date with the following code. <cfoutput query='Shbxordersdue'>
    <cfif #dateformat(suporder_duedate, 'dd/MM/yyyy')# EQ #dateformat(NOW(),
    'dd/MM/yyyy')#><tr bgcolor='##FFCCFF'><cfelse><tr></cfif> <td><a
    href='admin_supplier_orders.cfm?supplier=#supplier _ID#&amp;action=view&amp;supor
    der_refid=#suporder_refID#'>#supplier_name#</a> - <cfif
    #dateformat(suporder_duedate, 'dd/MM/yyyy')# EQ #dateformat(NOW(),
    'dd/MM/yyyy')#> <span class='style3'>Due: Today</span> <cfelseif
    #dateformat(suporder_duedate, 'dd/MM/yyyy')# GT #dateformat(NOW(),
    'dd/MM/yyyy')#> Due: #dateformat(suporder_duedate, 'dd/MM/yyyy')#
    <cfelseif #dateformat(suporder_duedate, 'dd/MM/yyyy')# LT #dateformat(NOW(),
    'dd/MM/yyyy')#> <span class='style2'>Over Due: #dateformat(suporder_duedate,
    'dd/MM/yyyy')#</span> </cfif> </td> </tr> </cfoutput> But
    the output is something like this.... Shopboxuk Orders Outstanding Eupa
    Trading Ltd - Due: 04/04/2005 Eupa Trading Ltd - Over Due: 03/04/2005 Eupa
    Trading Ltd - Due: Today Eupa Trading Ltd - Due: Today Eupa Trading Ltd -
    Due: Today Eupa Trading Ltd - Over Due: 30/03/2005 Eupa Trading Ltd - Over
    Due: 30/03/2005 Eupa Trading Ltd - Over Due: 30/03/2005 Eupa Trading Ltd -
    Over Due: 30/03/2005 Eupa Trading Ltd - Over Due: 29/03/2005 It has
    shown orders due today correctly, and that order at the top due on the 4th
    April...but the date of 03/04/2005 is shown as overdue, incorrectly. It
    manages to list it correclty in the order of dates... and puts it in the right
    place. But why has it done the calculation wrong, and i can only assume it has
    read it as 4th March. Thanks, Dan

    Stormpool Guest

  2. Similar Questions and Discussions

    1. #39668 [NEW]: date conversion failure
      From: mehmety at gmail dot com Operating system: Linux PHP version: 5.2.0 PHP Bug Type: Date/time related Bug description: ...
    2. Date comparison in a text data field
      I have a database column field defined as a text. I store dates in format: dd/mm/yyyy. The user passes a Start date search string in the same...
    3. Access SQL- Date comparison problem
      I use an Access-database where one column stores a date originating from this code: Indate = FormatDateTime(date(),vbgeneraldate) I then want...
    4. Date comparison and file download
      My goal, I would like to Compare the date of a file (one on the local drive, one on a remote server/url), if a newer resides on the server/url, then...
    5. Date comparison :: Original price vs Reduced price :: Access 2000/ASP
      I need some guidance in how to control dates with regards price reductions in my product list inside an Access 2000 database. For instance: 1....
  3. #2

    Default Re: Date comparison failure

    Credit to Falconseye on [url]www.easycfm.com[/url] forums. use DateCompare(date1, date2)
    returns - 1 if date1 < date2 0 if date1 = date2 and
    1 if date1 > date2 My code with this implemented.. <cfoutput
    query='Shbxordersdue'> <cfset nowdate = dateformat(NOW(),
    'dd/MM/yyyy')> <cfset date = datecompare(suporder_duedate, nowdate)>
    <cfif date EQ 0><tr bgcolor='##FFCCFF'><cfelse><tr></cfif>
    <td><a
    href='admin_supplier_orders.cfm?supplier=#supplier _ID#&amp;action=view&amp;supor
    der_refid=#suporder_refID#'>#supplier_name#</a> - <cfif date EQ 0>
    <span class='style3'>Due: Today</span>
    <cfelseif date EQ 1> Due:
    #dateformat(suporder_duedate, 'dd/MM/yyyy')#
    <cfelseif date EQ -1> <span class='style2'>Over Due:
    #dateformat(suporder_duedate, 'dd/MM/yyyy')#</span> </cfif>
    </td> </tr> </cfoutput>

    Stormpool Guest

  4. #3

    Default Re: Date comparison failure

    If suporder_duedate is a date field, you can just compare the dates directly:

    <cfif suporder_duedate EQ Int((NOW())>...
    <cfelseif suporder_duedate GT Int((NOW())>...

    The problem you are having is that you are currently comparing string values
    in the format of dd/mm/yyyy. If you don't trust the above code, you will need
    to change your format to yyyy/mm/dd for the comparisons.

    Also, to avoid the 1 in a billion chance that Now() increments between the
    multiple comparisons (in which case it will confuse the crap out of you and
    will be difficult, if not impossible to debug), I set a local variable to Now()
    or Int(Now()) in your case and use this temp variable in all the comparisons so
    that it guarantees that all the comparisons use the same value:

    <cfset currentdt=Int(Now())>
    <cfif suporder_duedate EQ currentdt>...
    <cfelseif suporder_duedate GT currentdt>...


    Steve Sommers Guest

  5. #4

    Default Re: Date comparison failure

    My code failed today on 01/04/2005 as it thought it should compare it to 4th
    Jan :o/ But with your advice i rewrote a bit of the code <cfset
    nowdate = dateformat(NOW(), 'yyyy-MM-dd')> <cfset duedate =
    dateformat(suporder_duedate, 'yyyy-MM-dd')> <cfset date =
    datecompare(duedate, nowdate)> And now it's ok, tried the server on numerous
    dates and all works fine.

    Stormpool 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