-2

Having headache day again. Need to make some changes to some things and populate available stuff first. Basically from when something is open till it closes. And add available spots every 15 minutes.

I can get the start date and end date populating - but can't get the inside loop populating the increment times that need to be inserted... Little lost here... Any help is appreciated...

Start Date and End Date come from a cfform - works fine...

    Start Date:<br>
    <cfinput type="datefield" name="startDate" required="true" message="Start Date Required">
    <br><br>
    End Date:<br>
    <cfinput type="datefield" name="EndDate" required="true" message="End Date Required">


         <cfloop index="dtToday" from="#StartDate#" to="#EndDate#"> 
         <cfoutput>

         <br>#DateFormat(dttoday)#<br>

             <cfloop index="incr" from="#TimeFormat(sadd.topen)#" to="#TimeFormat(sadd.tclose)#" step="#CreateTimeSpan( 0, 0, sadd.increment, 0 )#"> 

             [#TimeFormat(incr)#]

              Do Database Insert of Date/Time at increments

             </cfloop>



         <cfset schdate = #DateAdd('d', 1, '#schdate#')#>
         </cfoutput>    
         </cfloop>
Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25
  • 1
    When you output the variable, do you see what you think you should see? – Dan Bracuk Oct 30 '14 at 16:38
  • See nothing - tried doing the step increment in a dateadd inside loop - still nothing... – Merle_the_Pearl Oct 30 '14 at 16:42
  • #TimeFormat(sadd.topen)# - #TimeFormat(sadd.tclose)# - #sadd.increment# minutes - getting me 06:00 - 00:00 and 15 mins – Merle_the_Pearl Oct 30 '14 at 16:44
  • Can you update your post to make it a stand-alone example that we can test in our own environment? It is difficult to know what results you are getting - and why - without knowing the exact values, and types, of the variables ie `#StartDate#`, `#sadd.topen#`, etcetera. – Leigh Oct 30 '14 at 16:49
  • Your outside loop has an index of dtToday, but at the end of that loop you change a variable called schDate. – Dan Bracuk Oct 30 '14 at 16:50
  • I use schdate dates - doesn't need to be there for example I guess - using other code that works when inserting specific date/time. Here I'm trying to populate the day(s) of only available stuff in time slots allocated open/close time - to prepopulate open slots... – Merle_the_Pearl Oct 30 '14 at 17:14

1 Answers1

0

I modified your code so that I could test it quickly. CF Live shows this to work in Railo and CF.

It isn't clear where your trouble is coming from because I didn't make any drastic changes to your code.

<!--- You can get rid of these two form declarations, and the sadd declaration. This was just mimicking your data. --->
<cfset form.startdate = "11/17/95">
<cfset form.enddate = "12/20/95">
<cfset sadd = {topen= "13:00", tclose= "17:00", increment = 15}>

<cfif isDate(form.startdate) and isDate(form.enddate)>
    <cfloop index="dtToday" from="#form.StartDate#" to="#form.EndDate#"> 
        <cfoutput>
            <br>#DateFormat(dttoday)#<br>
            <cfloop index="incr" from="#TimeFormat(sadd.topen)#" to="#TimeFormat(sadd.tclose)#" step="#CreateTimeSpan( 0, 0, sadd.increment, 0 )#"> 
                [#TimeFormat(incr)#] - Do Database Insert of Date/Time at increments<br>
            </cfloop>
            <!---<cfset schdate = #DateAdd('d', 1, '#schdate#')#>--->
        </cfoutput>    
    </cfloop>
<cfelse>
    One or both of the dates entered is invalid.
</cfif>

I changed:

  • I form scoped startdate and enddate, it shouldn't have any negative impact on your code, it just seemed logical that startdate. While this is proper practice, the only way it could be causing you issues is if you had variables in multiple scopes with the name of startdate and/or enddate. (Safety against that, and security against exploitation of that is exactly why scoping your variables is best practice).
  • For my sample data, I set start time to 13:00 (1:00 PM) and end time to 17:00 (5:00). You can also use normal format of "1:00 PM" and "5:00 PM".
  • I commented out schDate because its use wasn't apparent here.
  • I added a sadd scope to mimic what it seems like your data probably is. In the future, give samples of what your data actually looks like :)
Regular Jo
  • 5,190
  • 3
  • 25
  • 47