Search code examples
coldfusioncfmlcfloop

How can I replicate this loop in cfscript (for use in cf10 / railo)


I have this working nicely in tag format, but am trying to migrate everything into cfscript. How can I do this one? (essentially, it loops over from date1 to date2, and needs to be in 15 minute intervals.

<cfset from=now()>
<cfset to=dateadd("d", 1, from)>
<cfloop from="#from#" to="#to#" index="i" step="#CreateTimeSpan(0,0,15,0)#">
 ...stuff...
<cfloop>

It's how to specify the step bit which is getting me..


Solution

  • <cfscript>
      variables.dtNow = now();
      variables.dtTmrw = dateAdd('d',1,variables.dtNow);
    
      do {
        variables.dtNow = dateAdd('n',15,variables.dtNow);
        writeOutput(variables.dtNow);
      } while(variables.dtNow neq variables.dtTmrw);
    </cfscript>