Skip to main content
Participant
August 1, 2013
Answered

If statements and date ranges... Anyone know what to do? (Long Question)

  • August 1, 2013
  • 1 reply
  • 501 views

Hi everybody - kinda new here. I was hired at a web design company last year and have recently taken to learning ColdFusion - so I'm not 100% on the syntax. I always need help with if statements, so I'm hoping you guys will be willing to spread some knowledge.

Anyway to put this in context:

What I'm working on is a Calendar that allows you to register to attend an event, such as a corporate dinner, holiday party, or some such nonsense. It also processes ticket purchases through a 3rd party such as PayPal, and would look something like this when put on a web-page.

http://i.imgur.com/VLIVVh3.jpg

Here's the code that creates that display.

<table class="registerTablePrices" cellspacing=5>

     <cfloop query="registration_types">

       <cfif registration_types.esl_price gte 0>

       <tr>

         <td class="formlabel" nowrap>#registration_types.estName#:</td>

         <td><cfinput name="regType_#registration_types.estid#"  style="width:30px" value="0"/></td>

         <cfif registration_types.esl_price is 0>

         <td class="formlabel">  X Free</td>

         <cfelse>

         <td class="formlabel" style="width:90px">  X #dollarformat(registration_types.esl_price)#</td>

         </cfif>

         <td class="labelInfo">Enter number of attendees for this type.</td>

       </tr>

       </cfif>

     </cfloop>

  </table>

All the code says at the moment is to display events whose price is positive, or else list them as free.

Here is what I want - I want to make it so that the May 30th Late Registration will automatically be hidden if the date is BEFORE or AFTER May 30th.

http://i.imgur.com/E7wU1K1.jpg

I have assigned values to the registration types that I want to restrict by date...

They are registration_types.estStartDate and registration_types.estEndDate

AND the value that designates it as Restricted, registration_types.estRestricted - which would be used like this.

<cfif registration_types.estRestricted is 1>

* Then only show it between registration_types.estStartDate and registration_types.estEndDate

And that's where I run into my problem. I can't make it work with the first code you saw:

<table class="registerTablePrices" cellspacing=5>

     <cfloop query="registration_types">

       <cfif registration_types.esl_price gte 0>

       <tr>

         <td class="formlabel" nowrap>#registration_types.estName#:</td>

         <td><cfinput name="regType_#registration_types.estid#"  style="width:30px" value="0"/></td>

         <cfif registration_types.esl_price is 0>

         <td class="formlabel">  X Free</td>

         <cfelse>

         <td class="formlabel" style="width:90px">  X #dollarformat(registration_types.esl_price)#</td>

         </cfif>

         <td class="labelInfo">Enter number of attendees for this type.</td>

       </tr>

       </cfif>

     </cfloop>

  </table>

I'm going to have at least 4 special conditions going on at once and I lose it there.

If you read all that I'm sorry, it may be hard to fully understand  - I appreciate any help.

    This topic has been closed for replies.
    Correct answer p_sim

    I wasn't sure what you wanted to do. Perhaps, this:

    <cfif (registration_types.esl_price gte 0)

                        or (registration_types.estRestricted is 1 and ((current_date ge estStartDate) and (current_date le estEndDate)))>

    You can also compare the dates using dateCompare().

    <cfset current_date = dateFormat(now(), "mm/dd/yyyy") />

    <cfloop query="registration_types">

                <cfif (registration_types.esl_price gte 0)

                        or (registration_types.estRestricted is 1 and ((current_date ge estStartDate) and (current_date le estEndDate)))>

                        #registration_types.estName#:

                        <cfinput name="regType_#registration_types.estid#" value="0"/>

                        <cfif registration_types.esl_price is 0>

                                  X Free

                        <cfelse>

                                  X #dollarformat(registration_types.esl_price)#

                        </cfif>

                        Enter number of attendees for this type.

              </cfif>

    </cfloop>

    1 reply

    p_sim
    p_simCorrect answer
    Participating Frequently
    August 1, 2013

    I wasn't sure what you wanted to do. Perhaps, this:

    <cfif (registration_types.esl_price gte 0)

                        or (registration_types.estRestricted is 1 and ((current_date ge estStartDate) and (current_date le estEndDate)))>

    You can also compare the dates using dateCompare().

    <cfset current_date = dateFormat(now(), "mm/dd/yyyy") />

    <cfloop query="registration_types">

                <cfif (registration_types.esl_price gte 0)

                        or (registration_types.estRestricted is 1 and ((current_date ge estStartDate) and (current_date le estEndDate)))>

                        #registration_types.estName#:

                        <cfinput name="regType_#registration_types.estid#" value="0"/>

                        <cfif registration_types.esl_price is 0>

                                  X Free

                        <cfelse>

                                  X #dollarformat(registration_types.esl_price)#

                        </cfif>

                        Enter number of attendees for this type.

              </cfif>

    </cfloop>

    Participant
    August 2, 2013

    I got the issue solved today, thanks in part to your post.

    Thank you!!