Skip navigation
Currently Being Moderated

How can I loop instead of hardcoding this info

Jun 17, 2012 8:28 PM

Hi all

I have the following code, how can I cfloop and dynamically output this info instead of having to have each meeting time? Thanks

 

<cfselect name="MEETINGTIME" width="90" label="Time"onchange="UsersGrid.dataProvider.editField(UsersGrid.sele ctedIndex, 'MEETINGTIME', MEETINGTIME.selectedItem.data);">

                        <option value="None">None</OPTION>

                            <option value="05:30 AM">05:30 AM</option>

                            <option value="06:00 AM">06:00 AM</option>

                            <option value="06:30 AM">06:30 AM</option>

                            <option value="07:00 AM">07:00 AM</option>

                            <option value="07:30 AM">07:30 AM</option>

                            <option value="08:00 AM">08:00 AM</option>

                            <option value="08:30 AM">08:30 AM</option>

                            <option value="09:00 AM">09:00 AM</option>

                            <option value="09:30 AM">09:30 AM</option>

                            <option value="10:00 AM">10:00 AM</option>

                            <option value="10:30 AM">10:30 AM</option>

                            <option value="11:00 AM">11:00 AM</option>

                            <option value="11:30 AM">11:30 AM</option>

                            <option value="12:00 AM">12:00 AM</option>

                            <option value="12:30 AM">12:30 AM</option>

                            <option value="01:00 AM">01:00 AM</option>

                            <option value="12:00 PM">12:00 PM</option>

                            <option value="12:30 PM">12:30 PM</option>

                            <option value="01:00 PM">01:00 PM</option>

                            <option value="01:30 PM">01:30 PM</option>

                            <option value="02:00 PM">02:00 PM</option>

                            <option value="02:30 PM">02:30 PM</option>

                            <option value="03:00 PM">03:00 PM</option>

                            <option value="03:30 PM">03:30 PM</option>

                            <option value="04:00 PM">04:00 PM</option>

                            <option value="04:30 PM">04:30 PM</option>

                            <option value="05:00 PM">05:00 PM</option>

                            <option value="05:30 PM">05:30 PM</option>

                            <option value="06:00 PM">06:00 PM</option>

                            <option value="06:30 PM">06:30 PM</option>

                            <option value="07:00 PM">07:00 PM</option>

                            <option value="07:30 PM">07:30 PM</option>

                            <option value="08:00 PM">08:00 PM</option>

                            <option value="08:30 PM">08:30 PM</option>

                            <option value="09:00 PM">09:00 PM</option>

                            <option value="09:30 PM">09:30 PM</option>

                            <option value="10:00 PM">10:00 PM</option>

                            <option value="10:30 PM">10:30 PM</option>

                            <option value="11:00 PM">11:00 PM</option>

                            <option value="11:30 PM">11:30 PM</option>

                          </cfselect>

 
Replies
  • Currently Being Moderated
    Jun 18, 2012 4:40 AM   in reply to goodychurro1

    Use cfloop condition = "YourDateTime lte #MaxDateTime#"

     

    inside your loop use DateAdd to increment YourDateTime and use TimeFormat to display it.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2012 5:17 AM   in reply to goodychurro1

    Did it work when you ran it?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2012 9:33 AM   in reply to goodychurro1

    That's probably because you have an infinite loop.   Also, you are setting your two variables to strings instead of datetime objects.  This might cause unexpected results.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2012 11:06 AM   in reply to goodychurro1

    goodychurro1 wrote:

     

    #timeFormat(dateAdd('n', 30, YourDateTime),'hh:mm:ss tt')#

     

    That does not change the value of the #YourDateTime# variable. So the loop just runs until it crashes because

    the value of #YourDateTime# is always less than 11:30PM.  You need to increment the value on each loop and assign the new value to #YourDateTime#.

     

            <cfloop ....>

                    ...

                    <cfset YourDateTime = dateAdd('n', 30, YourDateTime)>

            </cfloop>

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2012 4:21 PM   in reply to goodychurro1

    I get all the times in half hour intervals from 8 - 5.30 but in the wrong date!! {ts '1899-12-30 08:00:00'}

     

    It is not the wrong date.  Since you only specified a time (ie "07:30AM") the "date" portion defaults to 0 or 12/30/1899 .  If you needed a specific time and date, you must specify it when creating the variables. For example:

     

          <cfset YourDateTime = createDateTime(2012, 6, 25, 7, 30, 0)> ... or

          <cfset YourDateTime = parseDateTime("2012-06-25 07:30AM")>

     

    BUT .. in your case it does not make a difference because you are not using the date for anything. So just use timeFormat() to display the time only.

     

         ie     #timeFormat( yourVariableName,  'hh:mm:ss tt')#

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points