Skip to main content
Participant
April 25, 2008
Question

Compound condition with cfif

  • April 25, 2008
  • 3 replies
  • 599 views
I am creating a page for ambulance patient off-load times (USOL). The time is measured in seconds and I want to present it as either mm:ss or hh:mm:ss depending on whether it takes more than an hour or less. So my logic is:

if less than 1 second then - (nothing)
If >=1 and < 3600 seconds then format as mm:ss
if >3600 seconds then format as hh:mm:ss

My code snippet is:

<td>
<cfif USOL lt 1> -
<cfelseif USOL gte 1 AND USOL lt 3600> #timeformat((USOL/86400),"mm:ss")#
<cfelse USOL gte 3600> #timeformat((USOL/86400),"hh:mm:ss")#
</cfif>
</td>

Coldfusion 8 chokes on this. Is my syntax wrong? Is there a better way of doing this?
    This topic has been closed for replies.

    3 replies

    Inspiring
    April 25, 2008
    Ian Skinner wrote:
    > Kulp wrote:
    >> I am creating a page for ambulance patient off-load times (USOL). The
    >> time is measured in seconds and I want to present it as either mm:ss
    >> or hh:mm:ss depending on whether it takes more than an hour or less.
    >> So my logic is:
    >>
    >> if less than 1 second then - (nothing)
    >> If >=1 and < 3600 seconds then format as mm:ss
    >> if >3600 seconds then format as hh:mm:ss
    >>
    >> My code snippet is:
    >>
    >> <td>
    >> <cfif USOL lt 1> - <cfelseif USOL gte 1 AND USOL lt 3600>
    >> #timeformat((USOL/86400),"mm:ss")#
    >> <cfelse USOL gte 3600> #timeformat((USOL/86400),"hh:mm:ss")# </cfif>
    >> </td>
    >>
    >> Coldfusion 8 chokes on this. Is my syntax wrong? Is there a better
    >> way of doing this?
    >>
    >
    >
    > If I recall correctly timeFormat() only takes a time object, not on
    > integer representing seconds. I would probably do something along these
    > lines.
    >
    > <cfif USOL lt 1>
    > -
    > <cfelseif USOL gte 1 AND USOL lt 3600>
    > #int(USOL/60)# : #USOL mod 60#
    > <cfelse USOL gte 3600>
    > #int(USOL/3600)# : int((USOL MOD 3600)/60) : #USOL mod 3600#
    > </cfif>
    >

    Ok, I knew I had that hh:mm:ss calculation off:

    #seconds# - Hours:#int(seconds/3600)# Minutes:#int((seconds mod 3600) /
    60)# Seconds: #(seconds mod 3600) mod 60#
    Inspiring
    April 25, 2008
    The CFELSE line (gte 3600) should not have a criteria expression - it should just be <CFELSE> since that is what will be executed if no previous criteria matches.


    Try: (untested)

    <cfif USOL lt 1> -
    <cfelseif USOL gte 1 AND USOL lt 3600> #timeformat((USOL/86400),"mm:ss")#
    <cfelse> #timeformat((USOL/86400),"hh:mm:ss")#
    </cfif>

    Inspiring
    April 25, 2008
    Kulp wrote:
    > I am creating a page for ambulance patient off-load times (USOL). The time is
    > measured in seconds and I want to present it as either mm:ss or hh:mm:ss
    > depending on whether it takes more than an hour or less. So my logic is:
    >
    > if less than 1 second then - (nothing)
    > If >=1 and < 3600 seconds then format as mm:ss
    > if >3600 seconds then format as hh:mm:ss
    >
    > My code snippet is:
    >
    > <td>
    > <cfif USOL lt 1> -
    > <cfelseif USOL gte 1 AND USOL lt 3600> #timeformat((USOL/86400),"mm:ss")#
    > <cfelse USOL gte 3600> #timeformat((USOL/86400),"hh:mm:ss")#
    > </cfif>
    > </td>
    >
    > Coldfusion 8 chokes on this. Is my syntax wrong? Is there a better way of
    > doing this?
    >


    If I recall correctly timeFormat() only takes a time object, not on
    integer representing seconds. I would probably do something along these
    lines.

    <cfif USOL lt 1>
    -
    <cfelseif USOL gte 1 AND USOL lt 3600>
    #int(USOL/60)# : #USOL mod 60#
    <cfelse USOL gte 3600>
    #int(USOL/3600)# : int((USOL MOD 3600)/60) : #USOL mod 3600#
    </cfif>