Using <CFIF> to compare two set of time

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

  1. #1

    Default Using <CFIF> to compare two set of time

    I am using <cfif> to compare two set of time, if there is a match then display
    link. I am doing something wrong because it not displaying a link even thought
    there is a match. I using Access database, any assistance is greatly
    appreciated!

    Here is my code:

    <CFQUERY DATASOURCE="testDB" NAME="gettasks">
    select id, event_name, from_date
    from calendar
    where from_date >= ###dateformat(daterequest,'mm/dd/yyyy')###
    AND from_date <= ###dateformat(daterequest,'mm/dd/yyyy')###
    </CFQUERY>

    <CFSET startTime = CreateTime(0,0,0)>
    <CFSET endTime = CreateTime(23,59,59)>

    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" STYLE="border-collapse:
    collapse" WIDTH="100%" ID="AutoNumber1">
    <CFLOOP FROM="#startTime#" TO="#endTime#" INDEX="i"
    STEP="#CreateTimeSpan(0,1,0,0)#">
    <CFOUTPUT>
    <TR>
    <TD WIDTH="6%" HEIGHT="20" onClick="javascript:
    popup('addevent.cfm?addDate=#daterequest#&addTime= #TimeFormat(i, "h:mm tt")#')"
    VALIGN="TOP" ALIGN="right" BGCOLOR="##A0AB84" CLASS="smallWtext"
    STYLE="cursor:pointer;cursor:hand; border-left: 1px solid ##EAEAEA; border-top:
    1px solid ##EAEAEA; border-right-style:double;
    border-right-width:3">#TimeFormat(i, "h tt")#&nbsp;</TD>
    <TD WIDTH="94%" HEIGHT="20" STYLE="border-right:1px solid ##EAEAEA;
    border-top:1px solid ##EAEAEA; border-bottom-style: dotted;
    border-bottom-width: 1" BGCOLOR="##FFFFEB" CLASS="text">
    <CFLOOP QUERY="gettasks"><!---problem can't match time --->
    <CFIF TimeFormat(from_date, "h tt") is "#TimeFormat(i, "h tt")#">&nbsp;
    <A HREF="editevent.cfm?id=#id#&daterequest=#datereque st#">?
    #event_name#</A><BR></CFIF>
    </CFLOOP></TD>
    </TR>
    <TR>
    <TD WIDTH="6%" HEIGHT="15"
    onClick="window.location='daily.cfm?disp=add&addDa te=#daterequest#&addTime=#Time
    Format(i, "h:mm tt")#'; return true;" ALIGN="right" BGCOLOR="##A0AB84"
    STYLE="cursor:pointer;cursor:hand; border-left: 1px solid ##EAEAEA;
    border-right-style:double; border-right-width:3;<cfif #TimeFormat(i, "h tt")#
    is "11:00 pm"> border-bottom: 1px solid ##EAEAEA</cfif>">&nbsp;</TD>
    <TD WIDTH="94%" HEIGHT="15" STYLE="border-right: 1px solid ##EAEAEA;<cfif
    #TimeFormat(i, "h tt")# is "11:00 pm"> border-bottom: 1px solid
    ##EAEAEA</cfif>" BGCOLOR="##FFFFEB">&nbsp;</TD>
    </TR>
    </CFOUTPUT>
    </CFLOOP>
    </TABLE>


    phamtum Guest

  2. Similar Questions and Discussions

    1. Time Compare?
      I was wondering if anyone has done something like this and if so, please shed some light on this issue. I have an application that connects to an...
    2. cfif being ignored
      I wanted this to only execute if FORM.rp_image does not = defaultImg.gif but it seems to always run. I thought the syntax was okay but maybe not. ...
    3. compare date,time
      Hi, I have the following 12/08/2003, 11:00 13/08/2003, 23:00 Now I would like to compare them and then calculate the how long time was...
    4. Time compare using milliseconds
      Hello all, I have two timestamps that look like this: 08:42:38:624 08:42:39:437 I need to find out the difference. I have never worked with...
  3. #2

    Default Re: Using <CFIF> to compare two set of time

    Just curious... how can <b>from_date</b> be both greater than or equal to
    daterequest, <b>AND</b> less than or equal to daterequest ,at the same time?
    This statement will only return rows when from_date = daterequest.

    <CFQUERY DATASOURCE="testDB" NAME="gettasks">
    select id, event_name, from_date
    from calendar
    where from_date >= ###dateformat(daterequest,'mm/dd/yyyy')###
    AND from_date <= ###dateformat(daterequest,'mm/dd/yyyy')###
    </CFQUERY>

    Phil

    paross1 Guest

  4. #3

    Default Re: Using <CFIF> to compare two set of time

    My originally query was like this:

    <CFQUERY DATASOURCE="testDB" NAME="gettasks">
    select id, event_name, from_date
    from calendar
    where from_date >= ###dateformat(daterequest,'mm/dd/yyyy')###
    AND from_date <= ###dateformat(daterequest,'mm/dd/yyyy') 23:59:59:997###
    </CFQUERY>

    But this did not work, once I removed the time it worked fine. thanks for
    asking...

    phamtum Guest

  5. #4

    Default Re: Using <CFIF> to compare two set of time

    Since from_date is a date/time object containing a time component, it looks
    like you want to restrict your results to a single day (24 hour period). You
    left off the time part in your original post, so that is why it won't work.
    Since you are using Access, you could use the Access Format() function to
    remove the time component from your from_date as such:

    <CFQUERY DATASOURCE="testDB" NAME="gettasks">
    SELECT id, event_name, from_date
    FROM calendar
    WHERE Format(from_date, 'mm/dd/yyyy') = #dateformat(daterequest,'mm/dd/yyyy')#
    </CFQUERY>

    Since now you are comparing only date string to date string, you don't need to
    include a time range test.
    Phil

    paross1 Guest

  6. #5

    Default Re: Using <CFIF> to compare two set of time

    Thank you for your advice, unfortunately it did not work. I have simplified my
    codes to eliminate any other, but no luck.

    You ara absolutely right on your assessment, I am looking to pull all record
    with in a 24 hour period.

    Here is the new short version of the code with your suggestion:

    <CFPARAM NAME="daterequest" DEFAULT="#dateformat(now(), 'mm/dd/yyyy')#">

    <CFQUERY DATASOURCE="bradpha_ps" NAME="gettasks">
    select id, event_name, from_date
    from calendar
    WHERE Format(from_date, 'mm/dd/yyyy') = #dateformat(daterequest,'mm/dd/yyyy')#
    </CFQUERY>



    <CFSET startTime = CreateTime(0,0,0)>
    <CFSET endTime = CreateTime(23,59,59)>

    <CFLOOP FROM="#startTime#" TO="#endTime#" INDEX="i"
    STEP="#CreateTimeSpan(0,1,0,0)#">
    <CFOUTPUT>
    #TimeFormat(i, "h tt")#
    <hr>
    <br>
    <CFLOOP QUERY="gettasks">
    <CFIF #timeFormat(from_date, "h tt")# is "#TimeFormat(i, "h tt")#">&nbsp; ?
    #event_name#<BR></CFIF>
    </CFLOOP>
    </CFOUTPUT>
    </CFLOOP>


    Any other advice is greatly appreciated.

    Thanks from your help!!


    phamtum Guest

  7. #6

    Default Re: Using <CFIF> to compare two set of time

    Is your query returning the expected data? (Put <cfdump var=#gettasks#> right after your query to view the results)

    Phil
    paross1 Guest

  8. #7

    Default Re: Using <CFIF> to compare two set of time

    I get "query - Rows: 0".
    phamtum Guest

  9. #8

    Default Re: Using <CFIF> to compare two set of time

    Do you know, for a fact, that your database has rows where from_date matches the date that you are requesting?

    Phil
    paross1 Guest

  10. #9

    Default Re: Using <CFIF> to compare two set of time

    I am 100% sure that there is a date in my database that matches the requesting
    date. here is a copy of the database, I hope you can make it out.

    id event_name from-date
    from_time
    1 Brandon's 1st test 5/30/2006 11:00:00 AM 11:00:00 AM
    2 Brandon's 2nd test 5/30/2006 9:00:00 AM 9:00:00 AM
    3 Brandon's third test 5/30/2006 11:00:00 AM 2:00:00 PM
    5 Pick up Collin 5/31/2006 4:00:00 PM 4:00:00 PM
    7 Web Tool 5/31/2006 9:00:00 PM 9:00:00 AM
    10 my home page! 5/31/2006 8:00:00 AM 8:00:00 AM
    11 High Level Budget 5/29/2006 12:00:00 PM 12:00:00 PM
    12 Call Michael 5/29/2006 10:00:00 AM 10:00:00 AM
    13 Call CardServices 5/29/2006 10:00:00 AM 10:00:00 AM


    phamtum Guest

  11. #10

    Default Re: Using <CFIF> to compare two set of time

    OK, lets try a different direction. Keep from_date as a date/time object and
    use the createodbcdate() and createodbcdatetime() functions to convert your
    daterequest variable to date/time objects and use BETWEEN to compare the range.

    <CFQUERY DATASOURCE="bradpha_ps" NAME="gettasks">
    select id, event_name, from_date
    from calendar
    WHERE from_date BETWEEN #createodbcdate(daterequest)#
    AND #createodbcdatetime(daterequest+"23:59:59")#
    </CFQUERY>

    Phil

    paross1 Guest

  12. #11

    Default Re: Using <CFIF> to compare two set of time

    Phil,

    It worked, :D THANK YOU for your help!!
    phamtum 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