• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 96
  • Last Modified:

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!
0
tryport
Asked:
tryport
  • 4
  • 2
  • 2
2 Solutions
 
_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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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
 
_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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now