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

ColdFusion - Need to create a list of times in 15 minute increments

I need a drop down menu that displays a list of times that increment every 15 minutes.  So something like this:

12:00:00:AM
12:15:00:AM
12:30:00:AM
12:45:00:AM
01:00:00:AM
01:15:00:AM
01:30:00:AM
01:45:00:AM
02:00:00:AM
02:15:00:AM
02:30:00:AM
02:45:00:AM
03:00:00:AM
etc...

I have some code to do it but it ends up erroring after it hits 11:45:00:PM.  I've attached the code that I have and an image of the error.

I'm not married to this code so if you have another example that works please point me to it.

Thanks!
<cfset variables.minutes = "0,15,30,45">
<cfset variables.hours = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24">
 
    
<cfoutput>
<cfloop list="#variables.hours#" index="indexHours">
<cfloop list="#variables.minutes#" index="indexMinutes">
 <cfset variables.start_time = createTime(indexHours, indexMinutes, 00)>
 #timeformat(variables.start_time,"hh:mm:ss:tt")#<br />
</cfloop>
</cfloop>
</cfoutput>

Open in new window

calendar.gif
0
IRHusker
Asked:
IRHusker
  • 2
  • 2
1 Solution
 
erikTsomikSystem Architect, CF programmer Commented:
well the reason it is doing this because the the hourse reaches their end and the loop do not nop what to do next
0
 
SidFishesCommented:
http://www.coldfusionmuse.com/index.cfm/2008/9/17/cfloop.over.date.time

<ul>
<cfloop index="tm" from="8:00 AM" to="5:00 PM" step="#createTimespan(0,0,45,0)#">  
   <cfoutput> <li>#TimeFormat( tm, "h:mm TT" )#</li></cfoutput>
</cfloop>
</ul>
0
 
erikTsomikSystem Architect, CF programmer Commented:
http://www.bennadel.com/blog/684-Looping-Over-Times-In-ColdFusion.htm
<cfoutput>

<cfset dtHour = CreateTimeSpan(
0, <!--- Days. --->
0, <!--- Hours. --->
15, <!--- Minutes. --->
0 <!--- Seconds. --->
) />
 
 

<cfloop
index="dtTime"
from="8:00 AM"
to="8:00 PM"
step="#dtHour#">
 
#TimeFormat( dtTime, "hh:mm TT" )#<br />
 
</cfloop>
</cfoutput>
0
 
SidFishesCommented:
btw ... note the -cost- of the loop if you run it more than once in a single request
0
 
IRHuskerAuthor Commented:
Thanks bro!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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