8 Replies Latest reply: Jun 27, 2012 1:27 PM by goodychurro1 RSS

    cfif variable is query values

    goodychurro1 Community Member

      Hi all,

      In the last section of the code I am testing to see if meetingdate is a holiday, what is the correct way to do it , am I on the right track? Thanks

       

      <!--- QUERY TO GET HOLIDAY DATES --->
      <CFQUERY name="hols" datasource="salesdb">
      SELECT holiday, holidayid FROM holidays
      </CFQUERY>

      <!--- SET MEETINGDATE ACCORDING TO DAY OF THE WEEK --->
      <cfset meetingDate = trim(form.meeting)>
      <cfif not isDate(meetingDate)>
      <cfif DayOfWeek(Now()) eq 2>
      <cfset meetingDate = dateAdd("d", 2, now())>
      <cfelseif DayOfWeek(Now()) eq 3>
      <cfset meetingDate = dateAdd("d", 2, now())>
      <cfelseif DayOfWeek(Now()) eq 4>
      <cfset meetingDate = dateAdd("d", 2, now())>

       

      </cfif>
      </cfif>

       

      <!--- NOW CHECK IF NEW MEETINGDATE IS A HOLIDAY AND ADD DAYS--->

      <cfif meetingDate = hols.holiday >
      <cfif meetingDate eq 2>
      <cfset meetingDate = dateAdd("d", 3, now())>
      <cfelseif meetingDate eq 3>
      <cfset meetingDate = dateAdd("d", 3, now())>
      <cfelseif meetingDate eq 4>
      <cfset meetingDate = dateAdd("d", 2, now())>

       

      </cfif>

        • 1. Re: cfif variable is query values
          Dan Bracuk Community Member

          You appear to be missing a function call in the bottom part of your code.  It also appears to be incomplete.  You don't have anything for Thursday and Friday.

          • 2. Re: cfif variable is query values
            goodychurro1 Community Member

            Hi Dan

            I got rid of  Thursday , Friday , Saturday and Sunday to make the code easier to read. What function call am I missing?

            • 3. Re: cfif variable is query values
              Dan Bracuk Community Member

              If you want the code to be easier to read, consider using switch/case instead of if/else if/else. 

              • 4. Re: cfif variable is query values
                goodychurro1 Community Member

                Hi I'm going back to basics on this one, using a date that I know is in the hols query, then using listfind to see if it appears. I run the following code which should add 5 days to the meetingDate date as the 25th of December 2012 is a tuesday but it doesn't. Why not? Thanks

                 

                <CFQUERY name="hols" datasource="salesdb">
                SELECT * FROM holidays
                </CFQUERY>

                 

                <cfset meetingDate = '2012-12-25'>

                 

                <cfif ListFind(ValueList(hols.holiday), meetingDate)>

                 

                <cfif meetingDate eq 2>
                <cfset meetingDate = dateAdd("d", 2, now())>
                <cfelseif meetingDate eq 3>
                <cfset meetingDate = dateAdd("d", 5, now())>
                <cfelseif meetingDate eq 4>
                <cfset meetingDate = dateAdd("d", 2, now())>
                <cfelseif meetingDate eq 5>
                <cfset meetingDate = dateAdd("d", 4, now())>
                <cfelseif meetingDate eq 6>
                <cfset meetingDate = dateAdd("d", 3, now())>
                <cfelseif meetingDate eq 7>
                <cfset meetingDate = dateAdd("d", 2, now())>
                <cfelseif meetingDate eq 1>
                <cfset meetingDate = dateAdd("d", 1, now())>
                </cfif>


                </cfif>

                <cfdump var="#hols#"> 
                <cfoutput>#meetingDate#</cfoutput>

                • 5. Re: cfif variable is query values
                  Dan Bracuk Community Member

                  Why not? 

                   

                  You are checking to see if '2012-12-25' is 2, 3, 4, 5, 6, 7, or 1,  Which one did you expect to return true?

                  • 6. Re: cfif variable is query values
                    goodychurro1 Community Member

                    I expected this one to return true as 2012-12-25 is a tuesday:

                     

                    <cfelseif meetingDate eq 3>

                    <cfset meetingDate = dateAdd("d", 5, now())>

                    • 7. Re: cfif variable is query values
                      goodychurro1 Community Member

                      Ah sorry I forgot to check for day of the week! I'll try with this code and see!

                      <cfelseif DayOfWeek(meetingDate) eq 3>

                      • 8. Re: cfif variable is query values
                        goodychurro1 Community Member

                        worked it out, thanks for the help guys

                         

                        <CFQUERY name="hols" datasource="salesdb">
                        SELECT * FROM holidays
                        </CFQUERY>

                         

                        <cfset meetingDate = '2012-07-20'>

                        <cfoutput>#meetingDate#<br>
                        #DayOfWeek(meetingDate)#</cfoutput>

                         

                        <cfif ListFind(ValueList(hols.holiday), meetingDate)>

                        <cfif DayOfWeek(meetingDate) eq 2>
                        <cfset meetingDate = dateAdd("d", 2, meetingDate)>
                        <cfelseif DayOfWeek(meetingDate) eq 3>
                        <cfset meetingDate = dateAdd("d", 5, meetingDate)>
                        <cfelseif DayOfWeek(meetingDate) eq 4>
                        <cfset meetingDate = dateAdd("d", 2, meetingDate)>
                        <cfelseif DayOfWeek(meetingDate) eq 5>
                        <cfset meetingDate = dateAdd("d", 4, meetingDate)>
                        <cfelseif DayOfWeek(meetingDate) eq 6>
                        <cfset meetingDate = dateAdd("d", 3, meetingDate)>
                        <cfelseif DayOfWeek(meetingDate) eq 7>
                        <cfset meetingDate = dateAdd("d", 2, meetingDate)>
                        <cfelseif DayOfWeek(meetingDate) eq 1>
                        <cfset meetingDate = dateAdd("d", 1, meetingDate)>
                        </cfif>


                        </cfif>

                        <cfdump var="#hols#"> 
                        <cfoutput> #meetingdate# <br>
                        #DayOfWeek(meetingDate)#</cfoutput>