CFLOOP and output of TIME

I would like to output this time loop in increments of 20 per column and run it for a 24hr span. Logically, I figured 12:00 AM to 11:45 would work but it does not. I know I need a loop within this loop with a counter, but I'm having trouble figuring out the logic I need both for the time and for the from and to to move within <td>

<cfloop index="tm" from="12:00 AM" to="11:45 AM" step="#createTimespan(0,0,15,0)#">
<!-- counter -->
    <cfloop...>
      <td>
       <input type="checkbox" name="time1" value="#timeformat(tm, 'h:mm TT')#"> #TimeFormat( tm, "h:mm TT" )#<br />
      </td>
   </cfloop>
</cfloop>

Open in new window


Thanks in advance!
tryportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
You don't need an inner loop, but you do need to track the current row number with a counter.  See working example below.  It uses an integer counter instead of CreateTimeSpan which has some irritating rounding issues.

Edit: Since you'll ultimately be parsing the time on the server side, make the "value" as non-ambiguous as possible ie  HH:mm:ss.  That part isn't visible to the user anyway.

<cfset startTime = createTime(0,0,0)>
<cfset totalMinutes = dateDiff("n", startTime, createTime(11,45,0))>
<cfset rowNum = 0>


<table border="1">
<cfoutput>
totalMinutes = #totalMinutes#
<cfloop index="min" from="0" to="#totalMinutes#" step="15">
   <!--- get current time --->
   <cfset currentTime = dateAdd("n", min, startTime)>
   <cfset rowNum++>

   <!--- start new row every 20 values --->
   <cfif rowNum MOD 20 EQ 0>
      </tr><tr>
   </cfif>

   <td>
       <input type="checkbox" name="time1" value="#timeformat(currentTime, 'HH:mm:ss')#"> #TimeFormat( currentTime, "h:mm TT" )#<br />
   </td>
</cfloop>
</tr>
</cfoutput>
</table>

Open in new window

0
plusone3055Commented:
0
tryportAuthor Commented:
Thank you! Both of these are almost what I need but don't answer the question of a 24-hour cycle. I want 15 minute increments for a full 24 hours.
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

plusone3055Commented:
FROM
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-71a9.html

The following example displays the time in 30-minute increments, starting from midnight and ending 23 hours, 59 minutes, and 59 seconds later:


<cfset startTime = CreateTime(0,0,0)>  
<cfset endTime = CreateTime(23,59,59)>  
<cfloop from="#startTime#" to="#endTime#" index="i" step="#CreateTimeSpan(0,0,30,0)#">  
    <cfoutput>#TimeFormat(i, "hh:mm tt")#<br /></cfoutput> 
</cfloop>

Open in new window

0
_agx_Commented:
>  I want 15 minute increments for a full 24 hours.

My bad, I read 11:45 AM instead of PM.  I don't have time to test it, but it should work if you change the end time to 11:45 PM here, ie

          <cfset totalMinutes = dateDiff("n", startTime, createTime(23,45,0))>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_agx_Commented:
>  step="#CreateTimeSpan(0,0,30,0)#">

@plusone3055 - Agreed CreatetimeSpan seems simpler, but it has some annoying rounding issues with certain time values. Personally, I recommend avoiding it and using an INT loop instead.
0
tryportAuthor Commented:
Thanks!
0
_agx_Commented:
Welcome :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.